python terminate program – How to terminate a script?

python terminate program – Exit a Python Program in 3 Easy Ways Using quit() function, Python sys.exit() function and Using exit() function Example with demo.

python terminate program – How to stop/terminate a python script from running?

How to terminate a script? – To stop a running program, use Ctrl + C to terminate the process. A simple and effective method to exit a example in Python is to use the in-built quit() function.

Read Also:  Python Array Contains: How To Check If Item Exists In Array?

Example 1: Using quit() function

for ucode in range(1,10):
    print(ucode*10)
    quit()

Example 2: Python sys.exit() function

import sys 
 
ucode = 50
 
if ucode != 100: 
    sys.exit("Sorry, Values do not match")  
else: 
    print("Validation of values done!!") 

Example 3: Using exit() function

for ucode in range(1,10):
    print(ucode*10)
    exit()

Don’t Miss : pause in python

I hope you get an idea about python terminate program.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.