for...in...
while
for...in...
格式:for 参数 in 循环体: pass
例1:
#for 循环(遍历)
a1='Abce'
a2='apple'
a3=[1,2,3]
a4=[3,4,7,9]
#for i in 序列:
# i是临时变量
#
#range(start,end,step(增加的长度))
for i in a1:
print(i)
例2:
for i in range(1,10,2):
print(i,"次")
打印99乘法表
for i in range(1,10):
for j in range(1,i):
print(i,'*',j,'=',i*j)
while
格式:i = 0 while i >=10: pass i +=1
例:
#while 循环
b=1
while b<10:
print("b的值:", b)
if(b<5):
print("b还小余五呢\n")
b+=1