python 基础2-循环
while循环:
1、格式:
while 条件:
...
print(“...”)
2、while else的使用
3、continue、break
continue:终止当前循环,开始下一次循环
break:终止所有的循环
4、代码场景:
while else --while执行后再执行else n = 0 while n < 10: n+=1 print(n) else: print("else") print("---end---")
输入1-10,除了7continue --使用 n = 0 while n < 10: n+=1 if n == 7: continue print(n) print("---end---") # == n = 0 while n < 10: n+=1 if n == 7: pass else: print(n) print("---end---")
break --使用
continue与break --对比 n = 0 while n < 10: n+=1 print(n) continue print("123") print("---end---") 输出:1-10,end n = 0 while n < 10: n+=1 print(n) break print("123") print("---end---") 输出:1
相关推荐
CARBON 2020-04-21
sdwylry 2020-05-14
fanhuasijin 2020-04-25
晓杰0 2020-03-07
zhglinux 2020-01-31
zcabcd 2020-01-28
yogoma 2020-01-13
文山羊 2019-12-19
csuzilong 2019-04-26
编码即修行 2019-09-02
wangyaqi 2019-03-29
AKbiubiu 2010-07-12
mengsun 2015-08-13
Depth 2019-06-23
Tomhsfreestyle 2019-06-28
chaigang 2019-06-28
82483564 2011-04-20
Kiritow的学园 2019-06-13