Python 中 else语句的其他用法
来源:互联网 发布:佳能288清零软件 编辑:程序博客网 时间:2024/06/06 01:14
else 子句不仅能在 if 语句中使用,还能在 for、 while 和 try 语句中使用。
- for:仅当 for 循环运行完毕时(即 for 循环没有被 break 语句中止)才运行 else 块。
- while:仅当 while 循环因为条件为假值而退出时才运行 else 块。
- try:仅当 try 块中没有异常抛出时才运行 else 块。注意:else 子句抛出的异常不会由前面的 except 子句处理。
for i in range(5): print('for')else: print('end for')i = 0while i < 5: print('while') i += 1else: print('end while')try: print('check exceptions')except: raise ValueError('1')else: print('doing something after check')
在所有情况下,如果异常或者 return、 break 或 continue 语句导致控制权跳到了复合语句的主块之外, else 子句也会被跳过
阅读全文
0 0
- Python 中 else语句的其他用法
- python中else语句的用法
- Python中循环语句中的else用法
- python中else的用法
- Python中try...except...else的用法
- Python中try...except...else的用法
- Python中else的用法总结
- Python中else语句整理
- Python中else语句整理
- Python中else语句整理
- Python中if-else语句的多种写法
- Python中if-else语句的多种写法
- Python中if-else语句的多种写法
- Python中if-else语句的多种写法
- PHP的if...else语句的用法
- Python中try,except,else,finally用法
- Python的if...else...语句出错
- c#中数组,类型转换,using语句的其他用法
- [ICLR2017]Deep Biaffine Attention for Neural Dependency Parsing
- 单例模式
- Python时间序列LSTM预测系列教程(6)-单变量
- java 获取客户端真实ip方法
- 九、Shell echo命令
- Python 中 else语句的其他用法
- jquery监听由脚本改变input值的事件
- JAVA必须了解的基础知识
- HIVE学习笔记:HIVECLI操作(2)
- 利用HttpRequester进行接口测试
- Docker 学习系列 -- Docker 安装
- 数据结构基础【05】栈
- Nginx配置详解
- Keil(MDK-ARM)使用教程(二)_菜单