0 votes
1 view
in Python by (19.9k points)

In Python, there are two similarly-named functions, exit() and sys.exit(). What's the difference and when should I use one over the other?

1 Answer

0 votes
by (50k points)

The difference between exit() and sys.exit() in Python is as follows:-

So, If you use exit() in your code and run it in the shell, you will get the message that will ask whether you want to kill the program or not.

While using sys.exit() is better. It closes the program and it won’t create any dialogue box.

So there are two ways of looking at it the first is that, if you are pretty sure that you are ready to close your programme you don’t need to review it then you can use sys.exit() and it will directly close your programme.

The second way of looking at it is, if you are creating any app then you will use exit() function there because it may happen that the user may have pressed the close button by mistake in that case the pop-up window will come and ask whether you want to close it or not.

...