1、for循环
lis=[1,2,3,4,5,6,7,8,9]
for i in lis:
print(i)
2、range(start,stop,step) python的内置函数,start<=value<=stop
求1-100所有的偶数
for i in range(0,101,2):
print(i)
# for 循环写法
for i in range(1,101):
result = i % 2
if result==0:
print(i)
# while 循环写法
i=1
while i<=100:
result = i % 2
if result==0:
print(i)
else:
pass
i = i + 1
3、函数
函数定义: def func():
调用:func()
return:返回结果,只要return返回之后,后面的代码都不会执行了
形参:func(a,b)
实参:func(3,4)
必备参数:func(a,b) 能够接受任意类型的对象,写了几个就必须要传几个
默认参数:func(3,4) 可以去传 如果传了 就拿传的参数,如果没传,就按默认的参数
去执行