Write Python. Understand every error.

Open the editor

Error guide · NameError

NameError: name is not defined

Python met a name (a variable or function) that it does not know.

Example

score = 95
print(scroe)

What Python says

NameError: name 'scroe' is not defined. Did you mean: 'score'?

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

Names must be spelled exactly as they were created, including capital letters. The error also appears if you use a variable before the line that creates it, or forget the quotes around text, so Python thinks the text is a variable name.

How to fix it

score = 95
print(score)

Output: 95

Tips

Learn the ideas behind it

Other common errors

Share this page: