🐍 Python errors

Python exceptions: ImportError, KeyError, TypeError, IndentationError and more.

CodeErrorWhat it means
AttributeError AttributeError: 'X' object has no attribute 'y' You accessed an attribute or method that doesn’t exist on that object type.
ImportError ImportError: cannot import name 'x' from 'y' The module was found, but the name you’re importing from it doesn’t exist — usually a version change or a cir…
IndentationError IndentationError: unexpected indent / expected an indented block Python’s block structure is broken — inconsistent indentation or mixed tabs and spaces.
KeyError KeyError: 'x' You accessed a dictionary key that doesn’t exist.
ModuleNotFoundError ModuleNotFoundError: No module named 'x' Python can’t find the module you import — it isn’t installed in the interpreter/virtualenv that’s running, or…
NameError NameError: name 'x' is not defined Python doesn’t know the name — it was never assigned/imported in this scope, or it’s misspelled.
TypeError: NoneType TypeError: 'NoneType' object is not subscriptable You used `[ ]` on a value that is `None` — typically a function that returned nothing.