循环
1.无限(死)循环
一般形式
while 条件判断: 代码段
举个列子:
a = 0 while a<10: a +=1 print(a) a-->>>10
当条件不满足 a<10时,退出循环打印a
while中也可以插入 else:
a = input('a = ') while a == 1: print('a = 1') break else: print(a != 1)
输入一个数,当a =1,输出为a =1
否者,输出为 a != 1
循环
1.无限(死)循环
一般形式
while 条件判断: 代码段
举个列子:
a = 0 while a<10: a +=1 print(a) a-->>>10
当条件不满足 a<10时,退出循环打印a
while中也可以插入 else:
a = input('a = ') while a == 1: print('a = 1') break else: print(a != 1)
输入一个数,当a =1,输出为a =1
否者,输出为 a != 1
转载于:https://www.cnblogs.com/jiangxiaolong-1996/p/9231324.html