Home โบ Python Error Explainer
Python Error Explainer
24 error pages: 9 deep dives + 12 exact-message fixesEvery page links to interactive fixes
Pick the error in your traceback
Each explainer below is a focused deep dive into one exception: what the message literally means, a real runnable example with its full traceback, the specific causes, a debugging routine, and free PyDebug problems where you repair that exact error in the browser.
NameError
name 'x' is not defined โ typos, definition order, and scope, decoded from the message itself.
TypeError
str + int, 'not callable', 'not iterable' โ one exception, five famous wordings, each decoded.
IndexError
list index out of range โ why len(list) is never a valid index, and the four loop shapes that cause it.
KeyError
the missing dictionary key โ exact-match rules, get() vs [] vs setdefault, nested-dict traps.
ValueError
invalid literal for int() โ right type, impossible value, and the unpacking variants.
ZeroDivisionError
division by zero โ almost always a missing-data bug wearing an arithmetic costume.
SyntaxError
invalid syntax โ why the caret points one line late, and the six causes behind almost every parse error.
IndentationError
expected an indented block โ the three wordings, and the invisible tabs-versus-spaces version.
AttributeError
object has no attribute โ reading the type in the message, and the NoneType trap behind most of them.
Fix the exact message in your traceback
These pages take the wording you actually see โ the full message, quotes and all โ and decode that one message end to end: what it means, a runnable example that raises it, the causes, the fix, and free practice where you repair that exact bug in the browser.
- 'int' object is not subscriptable โ the value in front of your brackets is a number, not a container.
- 'str' object does not support item assignment โ strings are immutable โ rebuild, replace, or go through a list.
- can only concatenate str (not "int") to str โ str() at the join, f-strings for sanity, and the input() trap.
- unsupported operand type(s) for +: 'int' and 'str' โ the same mixed-types bug when the number is on the left.
- list indices must be integers or slices, not str โ a key used on a list โ the JSON shape confusion decoded.
- 'int' object is not iterable โ for i in 5 needs a range(), and the count-vs-collection mix-up.
- unhashable type: 'list' โ lists cannot be dict keys โ the tuple fix and what hashable means.
- ValueError: invalid literal for int() with base 10 โ what int() refuses, and the try/except that makes conversion safe.
- too many values to unpack (expected 2) โ the star operator, maxsplit, and the split() habits that prevent it.
- IndexError: list index out of range โ why len(list) is never a valid index, and the empty-list bug behind it.
- 'NoneType' object has no attribute โ an in-place method or a missing return handed you None.
- ModuleNotFoundError: No module named โ not installed, misspelled, wrong environment, or a shadowing file.
- UnboundLocalError: local variable referenced before assignment โ assigning anywhere in a function makes the name local for the whole function.
- string indices must be integers โ a dict key used on a string: the dict-loop and json.loads mistakes.
- 'NoneType' object is not subscriptable โ sort() and append() return None, and so does a function with no return.
- can't multiply sequence by non-int of type 'str' โ input() returns text, so '5' * '3' is not 15.
- 'int' object is not callable โ sum = 0 overwrote the built-in, and the missing-operator variant.
- not enough values to unpack (expected 3, got 1) โ split() with a separator that is not in the string.
- IndentationError: unexpected indent โ stray leading spaces, tabs mixed with spaces, and pasted code.
- FileNotFoundError: No such file or directory โ the working-directory trap, hidden extensions, and the pathlib fix.
- ImportError: cannot import name โ the module was found, the name was not: circular imports and shadowing files.
- RecursionError: maximum recursion depth exceeded โ the missing base case, and when raising the limit is the wrong answer.
- unterminated string literal โ the missing quote, the trailing backslash, and multi-line strings done right.
- invalid character in identifier โ smart quotes and lookalike Unicode from Word, PDFs and chat apps.
- can only concatenate list (not "str") to list โ you meant append, not +.
- object of type 'int' has no len() โ numbers have no length, and the len(str(n)) digit count.
- not all arguments converted during string formatting โ % is also modulo, and the f-string fix.
- module has no attribute โ lazy submodules, circular imports and shadowing filenames.
- UnicodeDecodeError: 'utf-8' codec can't decode byte โ binary files, the wrong encoding, and the BOM.
- NameError: name 'true' is not defined โ true/false/null are JavaScript and JSON, not Python.
- TypeError: 'NoneType' object is not iterable โ the four ways None reaches a for loop, and the guard for each.
- SyntaxError: unexpected EOF while parsing โ EOF means the parser hit the end inside an unclosed bracket, string or block.
- ValueError: math domain error โ which math functions reject which inputs, and the cmath alternative.
- AttributeError: 'str' object has no attribute 'append' โ strings are immutable, and join is the correct way to build one.
- ValueError: could not convert string to float โ currency symbols, thousands commas, empty cells and the cleaning pipeline.
- IndexError: string index out of range โ the valid index range, and why slicing never raises but indexing does.
- IndentationError: expected an indented block โ the block header has a colon but no body โ and the pass fix.
- TypeError: '<' not supported between instances of 'str' and 'int' โ comparing text with numbers, and the sorting case that hides it.
- ValueError: time data does not match format โ strptime directives, the ISO 8601 shortcut and timezone traps.
- UnicodeEncodeError: can't encode character โ why utf-8 almost never fails, and the cp1252 and ascii cases.
- TypeError: cannot unpack non-iterable NoneType object โ a function returned None instead of a tuple โ find which return path.
- RuntimeError: dictionary changed size during iteration โ deleting keys inside a loop, and the four safe patterns.
How to read any Python traceback
Read it bottom-up: the last line names the exception and its message; the lines above show the call chain that led there, with the deepest (most useful) frame last. Two facts direct everything else: the exception type tells you which rule was broken, and the message payload โ the quoted name, key, index, or value โ tells you which piece of your data broke it.
Every message above is also collected, with the rarer exceptions, in the complete Python errors guide. For the searching-and-narrowing method itself, see the Python debugging guide.
Hindi เคฎเฅเค เคธเฅเค เคฐเคนเฅ เคนเฅเค? เคนเคฐ error เคเคพ เคเคธเคพเคจ explanation, example เคเคฐ browser practice Hindi Python errors guide เคฎเฅเค เคชเคขเคผเฅเคเฅค