Skip to Content

How To Quit Python When In Terminal

How do you quit out of Python when you’re in an interactive shell environment?

The easiest way to close the Python shell in Terminal is to issue the quit() command.

Here’s an example demonstrating how to exit from a terminal window using the a-Shell app on the iPhone:

As you can see from the example above I was able to access the Python interactive shell by entering python3 on the command line. This simple instruction invokes the Python REPL and enables the user to enter Python commands.

In this example, I’ve instructed Python to output the current working directory.

To exit from the interactive shell there are a variety of ways, and in this instance I exited by using the exit() command.

Here is another way of being able to exit the shell using a similar command called quit():

Both commands perform the same operation by quitting the current interactive shell environment in a terminal window.

Use Keyboard Shortcut

There is another easier way of being able to exit the interactive shell within a terminal window and that is by using the Ctrl-D keyboard shortcut.

To use this shortcut simply hold down the Ctrl key on your keyboard and the tap the D keyboard key.


If you have opened the Python interactive shell from within a terminal window you can try one of 3 means of exiting out from the Python shell. On a new prompt row enter the command exit() or quit(), or use the keyboard shortcut Ctrl+D.