# -*- coding:utf-8 -*-
# for完整循环结构:
# for
# break
# else
# 常常用于遍历数据搜索
# 当for循环全部执行完成,没有被break打断时,else才会执行
students=[
{'name':'zhangsan'},
{'name':'lisi'},
{'name':'wangwu'}
]
find_name='wangwu'
for stu in students:
print stu
if stu['name'] == find_name:
print '找到了 %s' %find_name
break
else:
print '没有找到 %s' %find_name
Python学习-for break else完整for循环,用于搜索
最新推荐文章于 2025-07-07 21:23:04 发布