Errors & Exceptions

What each error means, why it happens, and how to fix it—with short, runnable examples. Quick debugging for real code.

When Python stops your program and prints an error message, it is not trying to confuse you—it is telling you exactly where and why something went wrong. This section is a reference for the most common errors you will see as a beginner or as you move into real projects. Each article explains the error in plain English, shows a typical cause with runnable code, and gives one or more ways to fix it.

Errors fall into a few broad groups. Name errors mean you used a variable or name that Python does not know (for example a typo or a name used before it is defined)—see NameError and UnboundLocalError. Type errors mean you used a value of the wrong type: calling something that is not a function (e.g. int not callable, list not callable), mixing numbers and strings (int and str), or using None where a list or dict was expected (NoneType has no len(), NoneType not subscriptable, NoneType not iterable). Index and key errors happen when you access a position or key that does not exist—IndexError: list index out of range, string index out of range, KeyError, and KeyError with nested dicts. Value errors usually mean the value you passed is invalid for the operation, such as invalid literal for int() or could not convert string to float.

Syntax and indentation errors (SyntaxError, IndentationError, TabError) come from the shape of your code rather than runtime values. File and import problems (FileNotFoundError, ModuleNotFoundError, ImportError, I/O operation on closed file, PermissionError) are about the environment and how you open or load resources. Understanding these categories helps you know which link to open when you see a traceback.

Use the list below to jump to the exact error. If you are new to Python, start with Getting Started and Data types so that type and name errors make more sense in context.