Skip to main content

Python: raise Keyword

The raise keyword is used to raise an exception and stops the execution of the programs. It is very useful when you want to work with the input validations.

Syntax:

if test_condition:
    raise Exception(Statement)

Example:

n = (int(input("Enter a number:")))
if (n%2==0):
    print("The given number is even")
else:
    raise Exception("The number is odd")
    

Output:

Enter a number:3
Exception: The number is odd
Tags
Submitted by devanshi.srivastava on July 8, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.