我有一个 while 循环的形式:
while temp is True:
do stuff
if the outcome is what I want:
temp = False
我似乎经常使用这个结构。所以我的问题是是否有一种方法可以在 while 语句本身中初始化 temp,而不是必须在其前面添加 temp = True
?
最佳答案
您可以使用:
while True:
do stuff
if the outcome is what I want:
break
关于python - 我可以为 python while 循环分配默认值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71195335/