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.


if test_condition:
    raise Exception(Statement)


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


Enter a number:3
Exception: The number is odd
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.


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.