What is a 'NameError' in Python, and how is it related to syntax errors?

Question

Grade: Education Subject: Support
What is a 'NameError' in Python, and how is it related to syntax errors?
Asked by:
72 Viewed 72 Answers

Answer (72)

Best Answer
(305)
A `NameError` occurs when you try to use a variable that hasn't been defined yet. While not always a syntax error, it can often be caused by a syntax error – for example, misspelling a variable name. W3Schools examples often demonstrate this by attempting to use a variable before it's assigned a value.