我知道Python有else
循环功能:
for item in items:
# loop block
else:
# will execute if there is no exception or break in loop block
由于这个特性,我想知道 python 中的循环是否还有其他智能的东西。现在我想找到一种更好的方法(比通过变量)来查找循环 block 是否被执行(即使一次):
items = []
for item in items:
# loop block
if #loop block was executed:
print("Big brother is watching you!")
最佳答案
items = []
for item in items:
# loop block
if items:
print("Big brother is watching you!")
关于python - 有没有更好的方法(比通过变量)来查找循环 block 是否被执行(即使一次)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133236/