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.
Exercise 15-b
Type something so that Python gives a SyntaxError.
Exercise 15-c
Type something so that Python gives a TypeError.
Exercise 15-d
Type something so that Python gives a IndexError.
Exercise 15-e
Type something so that Python gives a KeyError.
Exercise 15-f
Type something so that Python gives a AttributeError.
Exercise 15-g
Type something so that Python gives a ValueError.
Value error occurs when you apply a function to a data type correctly but the content is not suitable for that operation. For example, you can apply int() to a string of numbers such as:
int(“111”)
but you can’t convert letters to integers so following won’t work:
int(“Hello”)
str = "moose"
ans_1 = int(str)