Written by:
In Python, there are a few ways to exit the terminal. We are going to show you the exit() method because it doesn't prompt for confirmation and the method name is self-explanatory.
Type the following on your terminal:
1exit()
But there are other ways to achieve this:
The exit()
command terminates Python in a safe way and stores your data correctly. It's important to write the ()
after the word, or Python could understand that you want to know what the exit
statement means.
1Use exit() or Ctrl-Z plus Return to exit
This is the reason why we're emphasizing the presence of the ()
at the end.
The syntax is quite straight-forward:
1exit()
The command quit()
follows the same syntax as exit()
. You'll need to add the ()
at the end or you'll receive the same message as before.
1Use quit() or Ctrl-Z plus Return to exit
Keyboard shortcuts are common use among us developers because they save time and make you work faster. Here you have the shortcuts for Windows and Unix Systems (Linux and MacOS).
Before pressing ctrl+z
to exit Python just make sure your Python terminal is the selected windows, and then press ctrl
, hold it down and press z
and then Return
. You will see a message:
1>>> 2[1] + 54212 suspended python
On Unix systems such as MacOS or Linux, ctrl+z
will not exit Python on the terminal.
The keyboard shortcut for exiting Python on these systems would be ctrl + d
and on these systems you don't need to confirm with return
because their terminal will receive and execute this command immediately.
We will do as we did with the Windows shortcut. Press and hold ctrl
and then press d
to exit Python from the terminal making sure the terminal is the selected window.