what's the use case of exit() and sys.exit() in python

In main():

It's recommand to use exit() 

 

In function/modules

It's recommand o use sys.exit().

Need to deal with the return code.

 

Unlike  exit()sys.exit() is considered good to be used in production code for the sys module is always available. The optional argument arg can be an integer giving the exit or another type of object. If it is an integer, zero is considered “successful termination”.

Note: A string can also be passed to the sys.exit() method.

 

Reference:

https://www.geeksforgeeks.org/python-exit-commands-quit-exit-sys-exit-and-os-_exit/

posted on 2022-05-17 22:44  guolongnv  阅读(23)  评论(0)    收藏  举报