Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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.

Related questions

0 votes
1 answer
0 votes
2 answers
asked Sep 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Oct 4, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer
asked Aug 24, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...