1,在if/else语句中,如果在if或者某个elif条件成立,那么执行这个条件下的命令,同时这一个回合的循环结束。即使后面还有elif满足条件也不会执行。
1 #!/usr/bin/env python3
2
3 a = 5
4 b = 3
5 c = 1000
6 d = -8
7
8 mark = 0
9 while mark < 10:
10 if a > 3 and b > 8:
11 print('first yes')
12 elif a > 3 and d < 6:
13 print('second yes')
14 elif c == 1000 and b > 0:
15 print('third yes')
16 else:
17 print('stop')
18 mark += 2
执行结果为:
second yes
second yes
second yes
second yes
second yes