How to exit from Python command line – Terminal

Hello, I just ran a Python program and I was wondering how can I exit from the command line so that I can type new commands or just simply quit the program.

So in this tutorial, I will show you how to get rid of or exit from the command line in Python. It will work in Visual Studio Code’s terminal as well. (Even in shell script)

If your Python program is in running mode in the terminal then hitting enter will not let you exit.

Method 1:

Just press Ctrl + z

Method 2:

write quit() and hit enter.

Method 3:

Write exit() and hit enter.

Method 4:

Press Ctrl + d

All the above methods will work fine on Mac, Windows, Linux, and all major operating systems.

This is helpful when you want to exit from your Python program in the terminal or VS code.

In my case, I just typed python3 to check my installed Python version and I stuck myself in the Python command line terminal.

Leave a Reply

Your email address will not be published. Required fields are marked *