Python中for循环搭配else的陷阱

编程知识 更新时间:2023-05-02 19:10:23

>When the items are exhausted (which is immediately when the sequence is empty), the suite in the else

clause, if present, is executed, and the loop terminates.

>A break statement executed in the first suite terminates the loop without executing the else clause’s suite.

A continue statement executed in the first suite skips the rest of the suite and continues with the next item,

or with the else clause if there was no next item.

 

根据官方文档说法:大意是说当迭代的对象迭代完并为空时,位于else的子句将执行,

而如果在for循环中含有break时则直接终止循环,并不会执行else子句。

转载于:https://wwwblogs/xiao-xue-di/p/9458886.html

更多推荐

Python中for循环搭配else的陷阱

本文发布于:2023-04-28 04:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/8359c4cf83e936f6f0a0367f09fc2bb4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:陷阱   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107755文章数
  • 27244阅读数
  • 0评论数