若for循环正常结束,则执行else,
若for循环break,则不执行else。
for item in container:
if search_something(item):
# Found it!
process(item)
break
else:
# Didn't find anything..
not_found_in_container()
若for循环正常结束,则执行else,
若for循环break,则不执行else。
for item in container:
if search_something(item):
# Found it!
process(item)
break
else:
# Didn't find anything..
not_found_in_container()