TL ; DR:
A
NameErroroccurs when Python sees a word it does not recognize. Some examples:Misspelling a function name:
prnt("Heyooo!") # NameError: name 'prnt' is not definedMisspelling a variable name:
animal = "parrot" print(anmal) # NameError: name 'anmal' is not definedWhen Python encounters a name error, it immediately stops executing your code and throws a
NameErrorinstead.
Full lesson:
Humans are prone to making mistakes. Humans are also typically in charge of creating computer programs. To compensate, programming languages attempt to understand and explain mistakes made in their programs.
Here are two common errors that we encounter while writing Python code:
The NameError:
A NameError occurs when the Python interpreter sees a word it does not recognize. Some examples:
1. Misspelling a function's name:
prnt("My name is Andy")
2. Using a non-existent variable / Misspelling a variable's name:
animal = "parrot"
print(aniimal)
When we run this code we'll get a NameError: name 'aniimal' is not defined.
Assignment
Follow the Coding Tutorial and let's practice with errors!
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. PRO is unlimited.
