I'll give you a detailed explanation on these:
1. The quit function is used to raise the SystemExit exception and it gives you a message:
>>> print (quit) Use quit() or use Ctrl-Z+ Return to quit >>>
This is for beginners trying to learn python. But you need to remember that you must not use the quit function in production code.
2. The exit function is more like a synonym for the quit function. Like the quit function, the exit function is also used to make python more user-friendly and it too does display a message:
>>> print (exit) Use exit() or use Ctrl-Z+Return to quit >>>
And also it must not be used in production code.
3. The sys.exit function is used to raise the SystemExit exception in background. This function has an advantage over the other two functions as it can be used in production code.
4. The os.exit function is used to exit the program without calling flushing stdio buffers, cleanup handlers, etc. Hence, it is only used in special cases.
Now, we see that all of the four methods are used to exit the program but you can't use the first two in production code and the last method is non-standard.
So mostly we use sys.exit function.
Be a Python Expert. Enroll in Python Programming Course by Intellipaat.