【发布时间】:2021-08-31 21:49:33
【问题描述】:
我正在用 Python 编写一个程序,我需要跳出 if else lop 而不跳出 while 循环。
当前代码(例如不完整的代码。不是完整的代码。):
class foo:
def __init__(self, time1, link)
while self.isItNow == False:
self.current_time = self.now.strftime("%H:%M")
print(self.current_time)
if str(self.current_time) == self.time1:
webbrowser.open(self.link, new=1)
self.isItNow = True
else:
print("Current Time =", self.current_time,". Retrying again in 5 seconds")
time.sleep(5)
break
我想打破 else 并重新开始 if 循环,但我不能这样做,因为它打破了 while 循环。
提前致谢!!!!
【问题讨论】:
-
if..else 不是循环......
标签: python python-3.x if-statement while-loop break