学习Python的第二天
循环结构:
for-in循环:
主要用于计数,真正的用途是用于可迭代对象:列表,元组,字典,集合
for i in range(10,0,-2):
print(i)
for i in range(0,10,2):
print(i)
eg:升序排列
a = [2,3,1]
a.sort()
print(a)
eg:九九乘法表
for i in range(1,10):
for j in range(1,i+1):
print('%d%d=%d'%(i,j,ij),end=' ')
print()
while循环:一般用while的时候只是适用于死循环
while 循环的格式:
while 条件:
pass
eg:循环输出十次hello
i=0
while i <10:
print('hello')
i +=1
python里面最大的软肋:精度丢失
python四剑客
numpy/pandas/scipy/matpiotlib
高阶语言写法简答,执行效率低,低阶语言算法麻烦,执行效率高
eg:
str_ = 'Joker is a good man'
i = 0
while i < len(str_):
print(str_[i])
i +=1
函数:
函数的作用是简化代码,当你需要重复执行某些代码时,并且有一些微小的改变,可以使用函数
格式:
def 函数名字 (参数):
执行体语句
return xxx