How to end a Python Program Explained
Posted in Python on January 17, 2023 by Jessica Rose ‐ 1 min read

ⓘ Sponsored by 10xer.co
To end a Python program, press one of the following keys depending on the type of operating system :
For Windows :
CTRL + C
For Mac Os
Control + C
How to End the Interactive Python Command-Line Session
To leave the interactive Python command-line session, press: For Windows :
CTRL + Z
For Mac OS :
Control + Z
Or run the exit() function in your session.
>>> exit()
How to Terminate a Python Script
To terminate a Python program from within the code, utilize the sys.exit() function.
- Always import the sys library
- Use sys.exit()
For example:
import sys
sys.exit()
ⓘ Sponsored by 10xer.co