๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_exception_nameerror.asp
Python NameError Exception
Python Examples Python Compiler ... Plan Python Interview Q&A Python Training ... The NameError exception occurs if you use a variable that is not defined....
๐ŸŒ
Purple Engineer
purpletutor.com โ€บ home โ€บ understanding code โ€บ python nameerror causes solutions and prevention
Python nameerror explained with debugging tips and variable resolution ๐Ÿ๐Ÿ”
March 25, 2026 - โ€œThe NameError exception occurs if you use a variable that is not defined.โ€ โ€” W3Schools, 2024 Source link ยท Python's case sensitivity makes even subtle differences problematic.
People also ask

What is a NameError in Python?
A NameError in Python is an exception raised when a local or global name is not found in the current scope. It typically happens when you try to use a variable, function, or module that hasn't been defined or imported. Understanding this error helps in debugging code by ensuring all names are properly declared before use.
๐ŸŒ
purpletutor.com
purpletutor.com โ€บ home โ€บ understanding code โ€บ python nameerror causes solutions and prevention
Python nameerror explained with debugging tips and variable ...
What causes a NameError in Python?
A NameError in Python is caused by attempting to use a name that hasn't been bound to any object in the current namespace. Common triggers include typos in variable names, referencing variables before assignment, or failing to import modules correctly. Scope limitations, such as using a local variable outside its function, can also lead to this error.
๐ŸŒ
purpletutor.com
purpletutor.com โ€บ home โ€บ understanding code โ€บ python nameerror causes solutions and prevention
Python nameerror explained with debugging tips and variable ...
What is the difference between NameError and AttributeError in Python?
A NameError occurs when Python cannot find a name in the local or global scope, such as using an undefined variable. In contrast, an AttributeError is raised when trying to access a non-existent attribute or method on an existing object. While NameError deals with unresolved names, AttributeError focuses on invalid attribute access on resolved objects.
๐ŸŒ
purpletutor.com
purpletutor.com โ€บ home โ€บ understanding code โ€บ python nameerror causes solutions and prevention
Python nameerror explained with debugging tips and variable ...
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ python nameerror
Python NameError | How NameError Works in Python with Examples
January 8, 2024 - NameError is a kind of error in Python that occurs when executing a function, variable, library, or string without quotes that have been typed in the code without any previous Declaration.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ handling-nameerror-exception-in-python
Handling NameError Exception in Python - GeeksforGeeks
July 1, 2026 - Traceback (most recent call last): File "<main.py>", line 1, in <module> NameError: name 'user_name' is not defined ยท Explanation: user_name has not been defined anywhere in the program.
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ builtin-exceptions โ€บ nameerror
NameError | Pythonโ€™s Built-in Exceptions โ€“ Real Python
NameError is a built-in exception that occurs when you try to use a variable or function name that isnโ€™t defined yet.
๐ŸŒ
Carleton University
cs.carleton.edu โ€บ cs_comps โ€บ 1213 โ€บ pylearn โ€บ final_results โ€บ encyclopedia โ€บ nameError.html
Error Encyclopedia | Name Error
NameError exceptions in Python are generally raised when you try to access a variable that you have not defined properly. This could happen because the variable truly hasn't been defined yet, or perhaps only be due to a slight typo.
๐ŸŒ
Medium
medium.com โ€บ @rayancrazer โ€บ name-error-in-python-69393dbeec04
Unlocking the Mystery of NameError in Python: How to Fix It
November 24, 2024 - In summary, NameError in Python occurs when you try to use a variable or function name that has not been defined yet or is out of scope.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ trypython.asp
W3Schools online PYTHON editor
Traceback (most recent call last): File "demo_list_del2.py", line 3, in <module> print(thislist) #this will cause an error because you have succsesfully deleted "thislist". NameError: name 'thislist' is not defined
Find elsewhere
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ what-is-a-name-error-in-python
What is a name error in Python - Altcademy.com
March 6, 2024 - In technical terms, this error is raised when your code refers to a name that hasn't been defined yet. It's Python's way of saying, "I don't know what you're talking about!" One of the most common causes for a NameError is simply misspelling ...
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python nameerror name is not defined solution
Python nameerror name is not defined Solution | Career Karma
December 1, 2023 - A NameError is raised when you try to use a variable or a function name that is not valid. In Python, code runs from top to bottom. This means that you cannot declare a variable after you try to use it in your code.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ errors.html
8. Errors and Exceptions โ€” Python 3.14.7 documentation
>>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (most recent call last): File "<stdin>", line 1, in <module> 4 + spam*3 ^^^^ NameError: name 'spam' is not defined >>> '2' + 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str
๐ŸŒ
Codementor
codementor.io โ€บ community โ€บ python errors: nameerror name is not defined and more
Python Errors: Nameerror name is not defined and more | Codementor
September 28, 2021 - The code above raised an error because line 3 is missing the closing parenthesis. You will encounter a nameerror ( name is not defined) when a variable is not defined in the local or global scope.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 73536966 โ€บ what-is-this-nameerror-and-how-do-i-fix-it
python - What is this NameError and how do I fix it? - Stack Overflow
I tried the coding example the book told me to try, but I get this NameError that I do not understand why it is an error. ... CopyFile "/Users/eric/Python Notes/Notes.py", line 1, in <module> name = input('What is your name?\n') File "<string>", line 1, in <module> NameError: name 'eric' is not defined
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-resolve-nameerror-in-python-417444
How to resolve NameError in Python | LabEx
This tutorial will guide you through understanding the NameError, identifying its causes, and providing practical techniques to resolve it, ensuring a smooth and efficient Python coding experience.
๐ŸŒ
Python Guides
pythonguides.com โ€บ nameerror-name-is-not-defined
NameError: Name is Not Defined in Python
September 3, 2025 - If you forget to import a module, Python wonโ€™t recognize it. # Wrong print(math.sqrt(25)) # Correct import math print(math.sqrt(25)) I once ran into this while working with U.S. financial data and forgot to import pandas. Always check your imports. Sometimes, you may not be sure if a variable exists. In such cases, you can handle it gracefully with try/except. try: print(city) except NameError: print("The variable 'city' is not defined yet.")
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ nameerror-name-plot-cases-simple-is-not-defined-how-to-fix-this-python-error
NameError: Name plot_cases_simple is Not Defined โ€“ How to Fix this Python Error
June 27, 2022 - You'll see what a NameError is, some code examples to show how/why the error occurs, and how to fix them. In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way.
๐ŸŒ
Rollbar
rollbar.com โ€บ home โ€บ how to solve an undefined variable nameerror in python
How to Solve an Undefined Variable NameError in Python
In Python, a variable is not created until a value is assigned to it. If an attempt is made to use a variable before it is defined, a NameError: name 'x' is not defined error is thrown.
Published: May 16, 2023
๐ŸŒ
CodeFatherTech
codefather.tech โ€บ home โ€บ blog โ€บ python error: name is not defined. letโ€™s fix it
Python Error: Name Is Not Defined. Let's Fix It - Codefather
December 8, 2024 - The Python NameError occurs when Python cannot recognise a name in your program. A name can be either related to a built-in function or to something you define in your program (e.g.
๐ŸŒ
OpenPython
openpython.org โ€บ home โ€บ articles โ€บ fix python nameerror: 'name is not defined' (step-by-step)
Fix Python NameError: 'Name Is Not Defined' (Step-by-Step) | OpenPython
May 30, 2026 - This sequential execution model is intuitive but trips people up when code is reorganised โ€” moving a line of computation above the variable assignments that it depends on immediately causes a NameError. If you move code around and start getting NameErrors, check whether all the variables it references are still defined before it. Python treats username, user_name, and usernme as completely separate names.