TypeError: 'int' / 'NoneType' object is not iterable (tested)

TypeError: 'int' object is not iterable and 'NoneType' object is not iterable mean you looped over something that isn't a collection. We ran every common trigger on Python 3.13.5, including the two variants with different wording, and tested the fixes.

1. The messages and what triggers them

def find_users(active):
    if active:
        return ["ann", "bob"]
    # no return here: the function returns None

tests = {
    "for over int":   lambda: [x for x in 5],
    "for over None":  lambda: [u for u in find_users(False)],
    "list(3.5)":      lambda: list(3.5),
    "sum(5)":         lambda: sum(5),
    "1 in 5":         lambda: 1 in 5,
}
for name, f in tests.items():
    try:
        f()
    except TypeError as e:
        print(f"{name}: {e}")
try:
    a, b = find_users(False)
except TypeError as e:
    print(f"a, b = None: {e}")
for over int: 'int' object is not iterable
for over None: 'NoneType' object is not iterable
list(3.5): 'float' object is not iterable
sum(5): 'int' object is not iterable
1 in 5: argument of type 'int' is not iterable
a, b = None: cannot unpack non-iterable NoneType object

Measured: anything that loops over a value raises it when the value is a single number or None: for, comprehensions, list(), sum(). Two variants say it differently: in gives argument of type 'int' is not iterable, and tuple unpacking gives cannot unpack non-iterable NoneType object. The type in quotes is what you actually got; the fix depends on whether that's an int or None.

2. 'int' object is not iterable: you meant range()

n = 3
try:
    for i in n:
        pass
except TypeError as e:
    print(e)
for i in range(n):
    print(i, end=" ")
print()

items = ["a", "b"]
try:
    for i in len(items):
        pass
except TypeError as e:
    print(e)
for i, item in enumerate(items):
    print(i, item)
'int' object is not iterable
0 1 2 
'int' object is not iterable
0 a
1 b

Measured: for i in n and for i in len(items) both fail, because a number isn't a sequence. Use range(n) to count, and enumerate(items) when you want positions and items together (better than range(len(items))).

3. 'NoneType' object is not iterable: something returned None

nums = []
nums = nums.sort()          # sort() sorts in place and returns None
print(nums)
try:
    for x in nums:
        pass
except TypeError as e:
    print(e)

nums = [3, 1, 2]
print(sorted(nums), nums.sort(), nums)
None
'NoneType' object is not iterable
[1, 2, 3] None [1, 2, 3]

Measured: list.sort() sorts in place and returns None, so nums = nums.sort() replaces your list with None and the error shows up later, at the loop. Use sorted(nums) for a new list. The same happens with any method that changes things in place (append, extend, reverse, random.shuffle), and with your own functions when one branch forgets to return (the find_users(False) case in section 1).

4. Fix: return the same type every time

import json

def find_users(active):
    if active:
        return ["ann", "bob"]
    return []                # always return the same type

print(find_users(False))
for u in find_users(False):
    print(u)

data = json.loads('{"users": null}')
for u in data.get("users") or []:   # null in JSON becomes None
    print(u)
print("done")
[]
done

Measured: a function that returns a list should return [] when there's nothing, not fall off the end. For data you don't control, such as JSON where null becomes None, or [] turns a missing or null value into an empty loop. Use that only where “nothing” is a valid answer; if None means something went wrong, raise an error that says so instead. See also NoneType object is not subscriptable, the same root cause with [] instead of a loop.

Frequently asked questions

What does TypeError: 'int' object is not iterable mean?

You looped over a single number. We measured it from for x in 5, for i in len(items), list() and sum(); use range(n) or enumerate(items).

What does 'NoneType' object is not iterable mean?

The value you're looping over is None, usually because a function didn't return anything on some path or you assigned the result of an in-place method like list.sort(). We measured both.

What does cannot unpack non-iterable NoneType object mean?

a, b = f() where f() returned None. We measured it from a function with a branch that has no return statement; return a tuple on every path.

Why does 'in' say argument of type 'int' is not iterable?

The right side of 'in' must be a container or string. We measured 1 in 5 raising that message; check the variable holds the collection you expected.

How do I loop safely over a value that might be None?

for x in value or []: ... We measured it handling a JSON null; use it only when None genuinely means 'no items'.

Written with AI assistance. Measured on 2026-10-09 with Python 3.13.5: iterating ints, floats and None via for, comprehensions, list(), sum(), the in operator and tuple unpacking; for i in len(); list.sort() assigned back; and the return-[] and 'or []' fixes. Every code block was run verbatim and its output pasted from that run. PlainHeaders is our extension; everything else here is built-in Python.