TypeError
TypeError: 'int' object is not iterable
Traceback
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(i)
TypeError: 'int' object is not iterableWhat causes this error
A non-iterable object (int, float, None, bool) was used where an iterable was expected — in a for loop, unpacking, or a function like list(), sum(), sorted().
How to fix it
Wrap the value in a list or tuple if needed. Check variable types — ensure lists have not been overwritten with non-iterable values. Use range() instead of plain integers in for loops.
Code that causes this error
for i in 5:
print(i)Fixed code
for i in range(5):
print(i)About TypeError
This TypeError is raised when you use a non-iterable object in a context that requires iteration: for loops, unpacking, `list()`, `tuple()`, `sum()`, `min()`, `max()`, `sorted()`, comprehensions, and the `*` unpacking operator. An object is iterable if it implements the `__iter__` method or the `__getitem__` method with integer keys starting from 0. The most common causes are passing an integer to a function expecting a list (e.g., `range` returns an iterable but a plain integer does not), using `sum(1, 2, 3)` instead of `sum([1, 2, 3])`, and accidentally overwriting a list variable with a non-iterable value.
The error message tells you exactly which type was not iterable, making diagnosis easy.
Common scenarios
Performing operations between incompatible types like strings and integers
Calling methods that return None and chaining operations on the result
Passing the wrong number or type of arguments to a function
Using bracket notation on objects that do not support indexing