At Python’s >>> prompt, type quit() and press Enter. You will return to the shell that launched Python.

quit()

Keyboard alternatives

  • Linux and macOS: Ctrl+D at the primary prompt signals end of input.
  • Windows console: Ctrl+Z followed by Enter signals end of input.
  • Incomplete input: if you see ..., use Ctrl+C to cancel the unfinished statement and return to the primary prompt, then quit.

Ctrl+C ordinarily interrupts execution; it does not mean “close every Python session.” Terminal, notebook and IDE shortcuts can differ.

Do not type shell commands at the Python prompt

A command such as python3 hello.py belongs at your shell prompt, not after >>>. Exit Python first, then run it. See why a terminal appears to run Python without output for the distinction between scripts and the interactive interpreter.

Inside a program

Use sys.exit() when your program needs to request exit. quit() and exit() are interactive conveniences normally added by site, not the recommended program API. Exiting also discards variables held only in that Python session; save important work to a file first.

If you meant to close the shell itself, see exiting Git Bash.

Sources and verification

Normal quit() and sys.exit() behavior is checked in subprocesses. Windows keyboard shortcuts are documented behavior, not a Windows test result.