【Python 3.6.1】循环语句-WHILE
一、while语法
1 2 3 4 |
while condition1: statement1 else statement2 |
二、while测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@dt xxf]# cat w1.py i = 0 while i<=10: print (i) i +=1 [root@dt xxf]# python w1.py 0 1 2 3 4 5 6 7 8 9 10 [root@dt xxf]# |
三、while else 测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@dt xxf]# cat w2.py i = 0 while i< 10: print (i) i +=1 else: print (i) [root@dt xxf]# python w2.py 0 1 2 3 4 5 6 7 8 9 10 [root@dt xxf]# |