
Predict
Name That Exception
Python has many built-in exception types, and the name tells you what went wrong:
| Exception | Meaning |
|---|---|
ValueError |
right type, but a bad value (int("lots")) |
TypeError |
the wrong type for the operation |
KeyError |
a dictionary key that doesn't exist |
IndexError |
a list position that doesn't exist |
ZeroDivisionError |
dividing by zero |
NameError |
a variable name Python has never seen |
FileNotFoundError |
opening a file that isn't there |
fuel = 5
message = "Fuel left: " + fuel
print(message)