The Python error TypeError: 'int' object is not iterable or TypeError: 'NoneType' object is not iterable occurs when code attempts a for loop, list comprehension, or tuple unpacking on a non-sequence variable that lacks an __iter__() magic method.

Common Causes & Code Fixes

fix_iterable.pypython
# CAUSE 1: Iterating directly over an integer instead of range()
# WRONG: for i in 5:
# FIX: Use range() for numeric loops
for i in range(5):
    print(f"Iteration {i}")
 
# CAUSE 2: Unpacking a function that returned None instead of a tuple/list
def fetch_user_data(user_id):
    if user_id <= 0:
        return None # Returns None on error
    return ("Alice", "admin@example.com")
 
# WRONG: name, email = fetch_user_data(-1) # Raises TypeError: 'NoneType' object is not iterable!
# FIX: Validate return result before unpacking
result = fetch_user_data(-1)
if result is not None:
    name, email = result
else:
    print("Failed to fetch user data.")