How to exit the Python interpreter in a terminal?
There are several ways of exiting the Python interpreter if it's used in the interactive mode. The exact ways depend on the operating system used to run the Python interpreter. However, the general way of exiting the interpreter is using the exit() function and pressing enter.
exit Python interpreter using exit() function
To exit the Python interpreter, type the exit() command and press enter.
# exit Python interpreter
The Python interpreter is exited and the computer returns to the general terminal.
keyboard shortcut for macOS
To exit() the Python interpreter on macOS or Linux, use the keyboard shortcut control + d
keyboard shortcut for windows
To exit() the Python interpreter on windows, use the keyboard shortcut ctrl + z and press enter.
If none of the options above work, something stopped working. Try to close the window or force close it.
In some cases, you have to use Ctrl + Break to close the window.