close

How to exit Python script in Command Prompt?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to exit Python script in Command Prompt in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to exit Python script in Command Prompt?

  1. How to exit Python script in Command Prompt?

    As you mentioned, ctrl+C does not work on your Windows 10 with Python 3.6, but it does work on my Windows 10 with Python 3.4. Therefore, you really need to try and see what works for you.

  2. exit Python script in Command Prompt

    As you mentioned, ctrl+C does not work on your Windows 10 with Python 3.6, but it does work on my Windows 10 with Python 3.4. Therefore, you really need to try and see what works for you.

Method 1

It indeed depends on the OS, and probably on the version of Python you are using.

As you mentioned, ctrl+C does not work on your Windows 10 with Python 3.6, but it does work on my Windows 10 with Python 3.4. Therefore, you really need to try and see what works for you.

Try the following commands, and keep the one that works:

  • ctrl+C
  • ctrl+D
  • ctrl+Z then Return

In addition, the following should work with any terminal:

  • exit() then Return
  • quit() then Return

Trivia: if you type quit and hit Return, the console tells you, at least for Python 3.4:

Use quit() or Ctrl-Z plus Return to exit

Method 2

For an embedded python (e.g. python-3.6.8-embed-win32quit() command does not work

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:17) [MSC v.1916 32 bit (Intel)] on win32
>>> quit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'quit' is not defined

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read