或者条件在python中的while循环中有效吗?我好像做不到。这是我的代码如何工作的示例。在
newslot = 3
moved = False
while newslot > 0 or moved != True:
enabled = query something on the database where slot = newslot
if enabled:
print 'do something here'
moved = True
else:
newslot-=1
print 'slot disabled'
所以当newslot的值为0时,它仍然继续进入while循环。 我好像少了点什么。在
or
工作正常。while
循环将继续,直到其条件为false。如果它的条件是与or
相连的两个独立条件,则只有当这两个条件都为false时,它才会为false。在循环将继续重复,直到
moved
为false,newslot
为<;=0。我猜在这种情况下您实际上希望使用and
,因为您希望在满足任一条件后停止循环。在相关问题 更多 >
编程相关推荐