How do you exit Python in the terminal?
Short answer: type exit() or quit() and press Enter. You can also use the keyboard: Ctrl + D on macOS and Linux, or Ctrl + Z and then Enter on Windows. Since Python 3.13 you can type just exit or quit, without parentheses.
>>> exit()
$If a script is running and you want to stop it, press Ctrl + C. Inside your own code, use sys.exit().
exit() closes the interactive Python, Ctrl + C stops a script that is running and sys.exit() ends your program from the code.
How to exit Python in every situation
| Where you are | How to exit |
|---|---|
Python >>> on macOS or Linux | exit(), quit() or Ctrl + D |
Python >>> on Windows | exit(), quit() or Ctrl + Z and then Enter |
| Python 3.13 or newer | Also exit or quit without parentheses |
| A script that is running | Ctrl + C |
| Inside your own code | sys.exit() |
The help> prompt | Type quit or press Enter on an empty line |
The ... prompt | Press Enter on an empty line, or Ctrl + C to cancel |
| IPython | exit, quit or Ctrl + D |
| Jupyter Notebook | There is no exit: use Kernel > Restart or Shut Down |
Exit with exit() or quit()
>>> exit()exit() and quit() do exactly the same thing: they close the interactive interpreter and take you back to your system prompt ($ on macOS and Linux, C:\Users\you> on Windows).
In Python 3.12 or older, typing exit without parentheses does not close Python. It only prints a reminder:
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exitOn Windows the message says Use exit() or Ctrl-Z plus Return to exit. Add the parentheses and Python closes. Since Python 3.13, the new interactive shell understands exit and quit on their own.
Exit with the keyboard
| System | Shortcut |
|---|---|
| macOS and Linux | Ctrl + D at an empty >>> prompt |
| Windows (Command Prompt or PowerShell) | Ctrl + Z, then Enter |
On macOS and Linux, Ctrl + Z does not close Python. It pauses it in the background and the shell shows something like zsh: suspended python3. Type fg to bring Python back and then exit with exit(), or end it from the shell with kill %1.
