python全栈开发知识点补充for else和while else如果不是除正常以外的其他方式退出循环,那么else语句就会被执行。
2024-10-18 21:25:31
如果不是除正常以外的其他方式退出循环,那么else语句就会被执行。
也就是循环体内没有break语句、return语句、和其他异常语句的执行。
for else
>>> for i in range(0,10):
if i > 10:
break;
else:
print "hello world";
输出:hello world
>>> for i in range(0,10):
if i > 5:
break;
else:
print "hello world";
没有输出
-------------------
即在for 循环中,如果没有从任何一个break中退出,则会执行和for对应的else
只要从break中退出了,则else部分不执行。
最新文章
- 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
- elasticsearch客户端连接选择
- CCF真题之窗口
- 会话标识未更新(AppScan扫描结果)
- Swiper之初识
- OBIEE 11g:Error:nQSError 36010 Server version 318 cannot read the newer version of the repository
- WebView的应用 持续积累
- Static Final用法
- CentOS 添加/绑定 IP
- u Calculate e
- Ch.3 Aray and String
- Mybatis框架的搭建和基本使用方法
- spring security 4 filter 顺序及作用
- Go学习——go+channel实战(转)
- java.lang.ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject的解决方法
- 小甲鱼零基础python课后题 P21 020函数:内嵌函数和闭包函数
- C#基本方法(瞎写写)
- 部署与管理ZooKeeper(版本有点老,3.4.3)
- linux查询公网ip
- Makefile introduction (very old presentation)