NameError
NameError
The NameError
is raised when you have referenced a variable, module, class, function, or some other name that hasn’t been defined in your code. The Python documentation defines when this exception is raised:
Raised when a local or global name is not found. (Source)
In the code below, greet()
takes a parameter person
. But in the function itself, that parameter has been misspelled to persn
:
>>>
>>> def greet(person): ... print(f'Hello, {persn}') >>> greet('World') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in greet NameError: name 'persn' is not defined
Comments (0)