首页 > 编程语言 > 详细

Python中for循环搭配else的陷阱

时间:2018-08-11 11:16:23      阅读:165      评论:0      收藏:0      [点我收藏+]

>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子句。

Python中for循环搭配else的陷阱

原文:https://www.cnblogs.com/xiao-xue-di/p/9458886.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!