for循环:
a = [11,22,33,44]for i in a: print (i)
结果:
11223344
while循环:
i=0while i < 3: #i: 0i->: 1i->: 2i->: 3i->: 4i->: 5x=0while x < 9: for x in range(0,10): if x ==6: continue #当x==6时,跳出当前循环,继续下一次循环 print("x->:”, x)
结果:
x->: 0x->: 1x->: 2x->: 3x->: 4x->: 5x->: 7 #缺少x->: 6x->: 8x->: 9
其他:
enumrate:
a = [“aa”,”bb”,”cc”,”dd”]for i in enumerate(a,5): #默认编号从0开始,可以手动变更 print (i)
结果:
(5, ‘aa’)(6, ‘bb’)(7, ‘cc’)(8, ‘dd’)
range:
1、
for n in range(1, 10): print (n)
结果:
123456789
2、
for x in range(0,20,4):print (x)
结果:
0481216#以4作为step,依次打印