TypePython Error

TypeError

TypeError: 'int' object is not iterable

Traceback

terminal
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    print(i)
TypeError: 'int' object is not iterable

What 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

Broken
for i in 5:
    print(i)

Fixed code

Fixed
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

1

Performing operations between incompatible types like strings and integers

2

Calling methods that return None and chaining operations on the result

3

Passing the wrong number or type of arguments to a function

4

Using bracket notation on objects that do not support indexing

Related errors