python3 for 循环中的 else 语句
来源:互联网 发布:2017淘宝热卖产品 编辑:程序博客网 时间:2024/06/04 17:55
引言
- 我们今天用for else讲述这么个小故事
简介
操作系统:window7 x64
编程IDE:Pycharm 2016.1.2
Python版本:3.6.1
编辑时间:2017年4月21日
版权所有:OE, 转载请注明出处:http://blog.csdn.net/csnd_ayo
- 引言
- 简介
- for else
- 简述
- 触发 else
- 不触发 else
- 总结
for else
简述
英文原文
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 is no next item.
中文译文
用break
关键字终止当前循环就不会执行当前的else
语句,而使用continue
关键字快速进入下一论循环,或者没有使用其他关键字,循环的正常结束后,就会触发else
语句。
触发 else
正常结束的循环
list = [1,2,3,4,5]for x in list: print(x)else: print("else")
使用 continue 关键字
list = [1,2,3,4,5]for x in list: continue print(x)else: print("else")
不触发 else
list = [1,2,3,4,5]for x in list: print(x) breakelse: print("else")
总结
for else语句可以总结成以下话。
如果我依次做完了所有的事情(for正常结束),我就去做其他事(执行else),若做到一半就停下来不做了(中途遇到break),我就不去做其他事了(不执行else)。
- 只有循环完所有次数,才会执行
else
。 break
可以阻止else
语句块的执行。
4 0
- python3 for 循环中的 else 语句
- Python循环中的else语句
- [Python]循环语句中的 else 子句
- Python中循环语句中的else用法
- 循环语句if(){}else{}、if(){}else if(){}...else{}、do{}while()、for(){}、with(){}break/continue语句
- Python 小技巧:for 循环后面接 else 语句
- python for else 循环
- 批处理中的for循环语句
- C#中的for循环语句
- Java中的循环语句:For
- python循环语句中的else,break和continue
- jquery循环语句if-else if-else
- pyhon 循环中的else
- python 循环中的else
- python3.x 简单的for语句循环案例
- Python3-while循环语句
- python013 Python3 循环语句
- Python3 循环语句
- pg学习_多表连接
- 统计概念总结
- 将一个网络分为两个子网 通过已知IP和子网掩码计算其同一网段的主机IP
- 工厂数据管理系统
- 多线程个人问题汇总
- python3 for 循环中的 else 语句
- 深夜切题——ly与lyon的终极巅峰对决
- Kidnapping Gym
- [LeedCode]274. H-Index
- 动态代理
- CCFCSP201409-1相邻数对
- 关于TP项目发布到SAE访问时候出现空白报错
- Java 自动装箱与拆箱的实现原理
- 数字图像的基本运算