在 Python 中停止無限迴圈的鍵盤指令是什麼?


任何迴圈都形成於執行一定次數或直到滿足一定條件為止。但是,如果該條件並未出現,迴圈將無限重複。需要透過生成鍵盤中斷強制停止此類無限迴圈。按 ctrl-C 停止執行無限迴圈

>>> while True:
print ('hello')


hello
hello
hello
hello
hello
hello
Traceback (most recent call last):
File "<pyshell#18>", line 2, in <module>
print ('hello')
KeyboardInterrupt

更新於:2020 年 2 月 26 日

347 次瀏覽

開啟您的 職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.