Python程序终止
python程序运行完,结果已经出来了,但是程序不退出,提示Ctrl-c终止程序,可以加什么代码,让它自动退出吗? 源代码??? 本帖最后由 suchocolate 于 2022-12-5 11:04 编辑常规主动提前退出程序,推荐用exit或抛出异常
for i in range(10):
print(i)
if i == 5:
exit()
# raise Exception('exit with 5')
或者断言
for i in range(10):
print(i)
assert not i == 5
不过最好先贴出你的代码,具体问题具体分析。
页:
[1]