Python NameError Exception
Definition and Usage
The NameError
exception occurs if you use a variable that is not defined.
You can handle the NameError
in a try...except
statement, see the example below.
Exception Handling
Example
Handling the NameError
in a try...except
statement:
try:
print(x)
except NameError:
print("Variable x is not defined")
except:
print("Something else went wrong")
Try it Yourself »