Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started
← Back to How to's
Edit on Github

How to exit Python in terminal

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()

Other ways to exit the python terminal

But there are other ways to achieve this:

Exit()

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()

Using quit()

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

Using shortcuts

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).

Using CTRL+z on Windows

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

Using CTRL+d on MacOS and Linux

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.