How to exit Python in the Terminal

In this short tutorial, we will show you how to exit the Python prompt while in the terminal.

How to exit Python in the Terminal

There are a couple of different methods that you can use to exit the Python interpreter while in the terminal, which I will go into detail below. The instruction for Linux or macOS is slightly different from Windows, so choose carefully.

Python Interactive Mode

The Python interpreter has an interactive mode that allows you to issue commands to Python. Using this mode, you can write code into the terminal and have immediate feedback from Python. The interactive mode may be the preferred method over using a Python script for some use cases.

The example below demonstrates using Python to print the solutions to some simple math problems.

Entering interactive mode for Python is very simple as you type “python, py, or python3 into the terminal. However, exiting interactive mode is a little different depending on your operating system.

To confirm that you are in interactive mode, you should see three arrows >>>.

Below is an example of entering Python interactive mode on Ubuntu.

Exit Python Terminal on Linux or macOS

You can type in quit() or exit() to exit out of Python while using the terminal on a Linux or macOS computer.

Ensure you include the paratheses; otherwise, Python will present you with a message with the correct ways to exit Python. Below is an example of not using paratheses.

Below is the correct way to exit Python in the terminal on a macOS or Linux computer.

On Linux and macOS, you should be able to use the CTRL + D shortcut to exit the Python prompt.

Below is an example of using CTRL + D to exit.

Exit Python Terminal on Windows

Like Linux and macOS, the quit() or exit() function will exit out of the Python prompt on Windows.

Below is an example of how you can exit Python in the command line on a Windows computer.

Unlike Linux and macOS, CTRL + D may not work on Windows. Instead, you will need to use CTRL + Z, then Enter to exit the Python prompt.

Below is an example of using CTRL + Z, then Enter to exit.

Conclusion

I hope you can now exit the Python prompt in the terminal without any issues. Knowing the correct method to exit the interpreter will come in handy if you use the terminal a lot in your workflow.

If you want to learn more about the Python programming language, we have plenty more tutorials you should check out. If you are starting with Python, we recommend following our getting started with Python tutorial.

Please let us know if you notice a mistake or an important topic is missing from this guide.

Print Friendly, PDF & Email
Spread the love

Server Status

Aradippou Chat 1 Chat 2 Larnaca Limassol Nicosia

Chat Links

Official Links.

1. Chat 1.
2. Chat 2.

Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:

Archives

Super Club Radio

Scroll Up