Python控制流与小实例
# while a=0 while (a<10): print("hello") a+=1 # for循环 a=['aa','b','cc','dd'] for i in a: print(i) . for i in range(0,10): print(i,"hello") . #中断语句,continue,break # break:全部退出 # continue:中断一次循环,继续下次循环 for i in range(0,10): if (i==5): break print(i,"hello") for i in range(0,10): if (i==5): continue print(i,"hello") # 乘法口诀 for i in range(1,10): for j in range(1,i+1): print(str(j)+"*"+str(i)+"="+str(i*j)+" ",end="") #end=""表示不换行 print() # 逆向乘法口诀 for i in range(9,0,-1): for j in range(1,i+1): print(str(j)+"*"+str(i)+"="+str(i*j)+" ",end="") print() . for i in range(9,0,-1): for j in range(i,0,-1): print(str(j)+"*"+str(i)+"="+str(i*j)+" ",end="") print()
end
Tag: Python Python基础