Python中pass、continue、break、exit()的区别

时间:2021-08-19 09:14:42

pass :不做任何事情,只起到占位的作用

continue: 跳出本次循环

break:结束循环

exit():结束整个程序

由于continue和break较简单,这里就不给出代码:


1 #!/use/bin/[ython
2
3 for element in "Python":
4 if element == "y":
5 pass
6 else:
7 print element
8
9 print "#" * 10
10
11 for element in "Python":
12 if element == "t":
13 exit()
14 else:
15 print element
16
17 print "#" * 10
18 for element in range(10):
19 print element
20
21