NameError
The exception raised when code uses a name that has not been assigned, or is misspelt, or is not visible from here.
In more detail
The message, such as name 'widht' is not defined, points at the unknown name. Common causes are a typo, wrong capitals, using a variable before assigning it, or using a function's local variable outside it. Like other runtime errors it appears only when the line runs.
Related terms
- variable — A name that refers to a value, created by assignment, such as width = 10.
- scope — The region of a program where a name can be seen and used.
- case sensitive — Treating capital and lower-case letters as different, so last, Last and LAST are three separate names.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
Taught in
- Variables And Assignment — Hands-on Python: Complete Video Course & Book
- Literals, Identifiers And Keywords — Hands-on Python: Complete Video Course & Book
- Local Scope And Global Constants — Hands-on Python: Complete Video Course & Book
- The Exception Family Tree — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Interpreter, Compiler, And What Counts As Syntax — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Methods And The self Parameter — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Closures: Functions That Remember — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep