Home >>Python Keywords >Python raise Keyword

Python raise Keyword

Python raise Keyword

Python raise keyword is used to raise an exception/error with a customized message and stop the program's execution.

Here is an example of Python raise Keyword:

z = -1
if z < 0:
raise Exception("no numbers below zero")

Output:
Exception: no numbers below zero
Example 2:

y = "hello"
if not type(y) is int:
sraise TypeError("Only integers are allowed")

Output:
Only integers are allowed

No Sidebar ads