问题描述
exit(0)
和 exit(1)
在 Python 中有什么区别?
What's the difference between exit(0)
and exit(1)
in Python?
我试着环顾四周,但没有在这些方面找到具体的问题.如果已经回答了,一个链接就足够了.
I tried looking around but didn't find a specific question on these lines. If it's already been answered, a link would be sufficient.
推荐答案
0 和 1 是退出代码.
0 and 1 are the exit codes.
exit(0)
表示没有任何错误/问题的干净退出
exit(0)
means a clean exit without any errors / problems
exit(1)
表示存在一些问题/错误/问题,这就是程序退出的原因.
exit(1)
means there was some issue / error / problem and that is why the program is exiting.
这不是 Python 特有的,而且很常见.非零退出代码被视为异常退出,有时,错误代码会指出问题所在.零错误代码表示成功退出.
This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit.
这对于其他程序、shell、调用者等了解您的程序发生了什么并相应地进行操作非常有用.
This is useful for other programs, shell, caller etc. to know what happened with your program and proceed accordingly.
这篇关于Python 中 exit(0) 和 exit(1) 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!