for 循环
for循环一般用于集合类型的遍历循环,可以结合着循环使用,自身不需要使用到闭包 closure
#'''
#循环可以结合break使用,break关键字用来执行跳出循环操作.
#for循环也可以配合else使用,只有for循环的方法体全部执行玩之后才会执行else
#'''
for i in range(1,5) #[1,5),可以使用
print(i)
if xxx:
print('')
# break
else:
pass # or print() or TODO else
while 循环
while循环与java中的循环类似,也需要借助外部变量,形成闭包
count = 1
while count<=5 :
# loop body
在python中,循环也是可以嵌套使用的,控制循环的方式与其他语言是差不多的。
ceng = 1 #表示层数
while ceng <=5: # 第一层循环,保证打印多少行
count = 1
while count <= ceng:
print('*' ,end='')
count+=1
print() # 换行
#'''
# 1*1=1
# 1*2=2 2*2=4
# 1*3=3 2*3=6 3*3=9
# 1*4=4 2*4=8 3*4=12 4*4=16
# 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
# 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
# 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
# 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
# 1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=8
# '''
i = 1
while i <= 9:
j = 1
while j <= i:
print('{}*{}={}'.format(j, i, i * j), end='\t')
j += 1
print()
i += 1
本文地址:https://blog.csdn.net/shufangreal/article/details/107138029
如对本文有疑问, 点击进行留言回复!!
老猿学5G:融合计费场景的离线计费会话的Nchf_OfflineOnlyCharging_Release释放操作
老猿学5G扫盲贴:中国移动5G融合计费漫游计费架构和路由方案
老猿学5G扫盲贴:与用户和终端相关的名词UE、SUPI、GPSI、PEI
三星以核心技术优势持续更新折叠手机,华为缺乏自主技术无力应对
基于OpenCV+Python的均值滤波,高斯滤波,中值滤波,双边滤波
网友评论