我自学python。我在这里遇到了一个问题......“人类玩家也可以随时通过按下 Control-D 序列来结束游戏。”我该怎么做。我应该使用什么样的功能? 谢谢。
最佳答案
你可以试试 sys.exit()
:
import sys
...
sys.exit()
还有一个更标准的 exit()
函数(您不需要为此导入任何东西)。但是,如文档中所述,这与 sys.exit()
之间存在一个显着差异:
Since
exit()
ultimately "only" raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted.
关于python - 如何在运行时结束python程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14107436/