Python中while和for循环语句的注意事项

时间:2024-10-12 09:10:08

while和for是python中常见的循环语句,下面简单介绍几点循环语句使用时的注意事项。

Python中while和for循环语句的注意事项

工具/原料

电脑、网络

python

循环语句:

1、for … else语句,for 中的语句和普通的没有区别,else 中的语句会在循环正常执行完的情况下执行。

Python中while和for循环语句的注意事项
Python中while和for循环语句的注意事项

2、while … else 也是一样。

Python中while和for循环语句的注意事项
Python中while和for循环语句的注意事项

3、continue,break这2个命令用来跳过循环,continue 用于跳过该次循环。

Python中while和for循环语句的注意事项
Python中while和for循环语句的注意事项

4、break 则是用于退出循环。

Python中while和for循环语句的注意事项
Python中while和for循环语句的注意事项
© 手抄报圈