🌐
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 'city' is not defined · Explanation: city is accessed before its assignment statement is executed, so Python cannot find the variable. 4. Incorrect Variable Scope: Variables defined inside a function are local to that function and cannot be accessed outside it. ... ERROR!
🌐
Medium
medium.com › @rayancrazer › name-error-in-python-69393dbeec04
Unlocking the Mystery of NameError in Python: How to Fix It
November 24, 2024 - Let’s take a closer look at some examples of NameError in Python and how to fix them. ... In this example, we try to use the variable z, which has not been defined yet. As a result, we get a NameError that looks like this: To fix this error, we need to define z before we try to use it.
Discussions

"NameError: name is not defined"... but it is?
So, im making a tic-tac-toe game and im nearly finished i think. im trying to make it so the game can be played more than just once before it ends. So i put it into a def() function… but running it results in NameError: name 'turn' is not defined. Any ideas why and how to fix this? def game(): ... More on discuss.python.org
🌐 discuss.python.org
9
0
October 27, 2021
NameError: name 'name' is not defined
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
14
11
July 24, 2022
"Name is not defined" Error [Beginner]
You should be getting an indentation error after def autoLimbTool(): for the code as posted. More on reddit.com
🌐 r/learnpython
9
0
August 26, 2024
NameError when variable has been defined
Stop using global variables and just pass your data using arguments and returns. That should fix it. More on reddit.com
🌐 r/learnpython
14
2
May 30, 2023
🌐
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 - Here we fail to put the string inside the quotes, so the console will throw us the NameError. ... The NameError can be avoided easily by using the Python Error handling technique or exception handling, which denotes the user about the NameError that is occurring in the block of code without actually throwing an error.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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 · The last line of the error message indicates what happened. Exceptions come in different types, and the type is printed as part of the message: the types in the example are ZeroDivisionError, NameError and TypeError.
🌐
W3Schools
w3schools.com › python › ref_exception_nameerror.asp
Python NameError Exception
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The NameError exception occurs if you use a variable that is not defined.
🌐
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 - The resulting error was this: NameError: name 'math' is not defined. This happened because the interpreter did not recognize the math keyword. Along with other math methods in Python, we must first import the math module to use it.
🌐
Real Python
realpython.com › ref › builtin-exceptions › nameerror
NameError | Python’s Built-in Exceptions – Real Python
When the interpreter displays a NameError, it also tries to suggest a fix. Since Python 3.10, a misspelled name gets a Did you mean: ...? hint, and since Python 3.12, an undefined standard-library name gets a Did you forget to import ...?
🌐
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 - For example, you will see this error if you try to print a variable that wasn’t defined. You might also see this error when you use a built-in library, but forget to import the library first. Let’s see a few code examples: ... Traceback (most recent call last): File line 4, in <module> print(num) NameError: name 'num' is not defined
Find elsewhere
🌐
AlgoCademy
algocademy.com › link
Name Errors in Python | AlgoCademy
This typically happens due to: Misspelling a function or variable name. Using a variable before it is defined. Referencing a variable that is out of scope. ... In this example, the function print is misspelled as prnt, leading to a NameError.
🌐
Rollbar
rollbar.com › home › what are the different types of python errors? – and how to handle them
Python Errors and How to Handle Them (With Examples)
Now the code will run without any errors, and the output will be 500, which is the element at index 4 of the list. An AttributeError occurs when you try to access an attribute or method that doesn't exist for a particular object type. This often happens due to typos or misunderstanding what methods are available for different data types. Here's an example of an AttributeError in Python: ... Traceback (most recent call last): File "c:\Users\name\OneDrive\Desktop\demo.py", line 2, in <module> my_string.reverse() ^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'reverse'
Published: August 10, 2026
🌐
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 - The code returns an error: "Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!" Venus, Software Engineer at Rockbot Find Your Bootcamp Match · Traceback (most recent call last): File "main.py", line 1, in <module> print(Books) NameError: name 'Books' is not defined · Python treats “Books” like a variable name.
🌐
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 - Python cannot find the name “calculate_nt_term” in the program because of the misspelling. This can be harder to find if you have written a very long program. Lesson 4: Verify that there are no misspellings in your program when you define or use a variable or a function. This also applies to Python built-in functions. You now have a guide to understand why the error “NameError: name …
🌐
Rollbar
rollbar.com › home › how to solve an undefined variable nameerror in python
NameError: name 'x' is not defined in Python
In this example, an undefined variable ... 'x' is not defined error in Python, you need to make sure that the variable is properly defined and assigned a value before it is used....
Published: May 16, 2023
🌐
Python Principles
pythonprinciples.com › blog › name-errors
Name Errors – Python Principles
The x in the error will vary depending on your program. The error means that Python looks for something named x but finds nothing defined by that name.
🌐
Altcademy
altcademy.com › blog › what-is-a-name-error-in-python
What is a name error in Python - Altcademy.com
March 6, 2024 - If there's no one by that name, you'll be met with silence or confused looks. Similarly, a NameError in Python occurs when you try to use a name (usually a variable or a function name) that Python doesn't recognize.
🌐
Carleton University
cs.carleton.edu › cs_comps › 1213 › pylearn › final_results › encyclopedia › nameError.html
Error Encyclopedia | Name Error
In this case, because we've misspelled “demetrius”, Python raises a NameError, letting us know that 'demetrius' wasn't defined. Python doesn't know that we've simply misspelled a variable name; as far as it is concerned, the variable wasn't defined and that's final.
🌐
Djmannion
djmannion.net › psych_programming › errors › errors › errors.html
Dealing with errors — Programming for Psychology in Python
What happens when your Python code contains an error? Here, we will have a look at what happens when we try and print the contents of a variable that we haven’t defined. ... Traceback (most recent call last): File "", line 1, in <module> print apples NameError: name 'apples' is not defined
🌐
Airbrake
blog.airbrake.io › blog › python › python-nameerror
Python Exception Handling - NameError
July 13, 2022 - As we know from executing the log_invalid_object function earlier, the CPython interpreter is unable to locate a global named valu during execution, so a NameError is raised to indicate as much. Neat! Airbrake's robust error monitoring software provides real-time error monitoring and automatic exception reporting for all your development projects.
🌐
Python.org
discuss.python.org › python help
"NameError: name is not defined"... but it is? - Python Help - Discussions on Python.org
October 27, 2021 - So, im making a tic-tac-toe game and im nearly finished i think. im trying to make it so the game can be played more than just once before it ends. So i put it into a def() function… but running it results in NameError: name 'turn' is not defined. Any ideas why and how to fix this? def game(): blanksheet = "|1|2|3|\n|4|5|6|\n|7|8|9|" sheet = blanksheet print(sheet) gone = [] turn = 0 def play(XO,player,listXO): global turn global sheet global listx global listo ...