码迷,mamicode.com
首页 > 编程语言 > 详细

Python中for循环搭配else的陷阱

时间:2018-08-11 11:33:51      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:文档   ted   first   items   media   which   for循环   lse   and   

>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的陷阱

标签:文档   ted   first   items   media   which   for循环   lse   and   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!