我们在 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 次浏览

开启你的 事业

通过完成课程获得认证

立即开始
广告