python terminate program – How to terminate a script?

Rate this post

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.

Free Live Chat for Any Issue

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:  How to connect Bitbucket version control in cPanel to install and update a site?

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

Download

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.