在 Python 中,我们可以使用什么键盘命令来停止无限循环?
pythonserver side programmingprogramming更新于 2025/8/10 14:04:17
任何循环都会执行一定次数或直到满足某个条件。但是,如果条件不成立,循环就会无限重复。这种无限循环需要通过生成键盘中断来强制停止。按 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
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

