Home >>Python Keywords >Python except Keyword
The except keyword in python is used to define a block of code to run if in case a try block raises an error. By using this keyword, you can execute blocks and different blocks for different error types if nothing went wrong.
Here is an example of Python except Keyword:
try:
x > 5
except:
print("All is not well")
print("Even if it raised an error, the program keeps running")
y = "hello"
try:
y > 5
except NameError:
print("variable that is not defined.")
except TypeError:
print(" comparing values of different type")