Python Error Handling Exercises

Let’s check out some exercises that will help understand Python Errors better.

Exercise 15-a

Type something so that Python gives a NameError.


You’ll get a NameError when an object can’t be found in Python.

Without defining zzz anywhere:
print(zzz)

Exercise 15-b

Type something so that Python gives a SyntaxError.


You’ll get a SyntaxError when you make a syntax error in Python. It can be a missing quote or parenthesis.

print("Hello World!"

Exercise 15-c

Type something so that Python gives a TypeError.


You’ll get a TypeError when you apply an operation or function to the wrong type of data, such as applying arithmetic operations to strings.

str = "Hello"
str = str + 5

Need More Exercises?

Check out Holy Python AI+ for amazing Python learning tools.

*Includes 14 more programming languages, inspirational tools and 1-on-1 consulting options.
Umut Sagir
Finance & Data Science Professional,
Founder of HolyPython