TypeError: 'bool' object is not iterable (Fix)

This error happens when Python expects something it can loop over, unpack, or check membership in, but gets True or False instead.

A boolean is only a single value:

  • True
  • False

It is not a collection like a list, string, tuple, set, or dictionary.

This guide shows what the error means, why it happens, and how to fix it based on what your variable should actually contain.

Quick fix

value = True

# Wrong:
# for item in value:
#     print(item)

# Fix: use a real iterable
items = [value]
for item in items:
    print(item)

Output:

True

A boolean is a single True/False value, not a collection. If you need iteration, use a list, tuple, string, set, or dictionary instead.

What this error means

Python raises this error when code expects something it can loop over.

This usually happens in places like:

  • for loops
  • membership tests using in
  • unpacking
  • functions that expect iterables

A bool only stores True or False, so Python cannot treat it like a group of items.

Example that causes the error

Here is a minimal example:

value = True

for item in value:
    print(item)

Python raises:

TypeError: 'bool' object is not iterable

Why? Because for item in ... only works with iterable values such as lists, strings, tuples, and dictionaries.

If you are new to loops, see Python for loops explained.

Why it happens

This error usually means your variable is not the type you thought it was.

Common reasons:

  • A variable contains a boolean when you expected a list or string
  • A comparison like x > 5 returns True or False, not multiple values
  • A function returns a boolean, but later code tries to loop over the result
  • A variable gets overwritten with True or False by mistake

Example: comparison result used like a list

x = 10
value = x > 5   # value becomes True

for item in value:
    print(item)

x > 5 is a condition. It does not create a collection.

To understand this better, see Python booleans explained: True and False.

Fix 1: Use the correct iterable value

First, check what the variable is supposed to contain.

If you meant to store multiple items, use a real iterable such as:

  • list
  • tuple
  • string
  • set
  • dictionary

Wrong

names = True

for name in names:
    print(name)

Correct

names = ["Alice", "Bob", "Charlie"]

for name in names:
    print(name)

Output:

Alice
Bob
Charlie

If the value came from a function

Make sure the function returns the data you need.

def get_names():
    return ["Alice", "Bob"]

names = get_names()

for name in names:
    print(name)

Output:

Alice
Bob

If you are not sure what a function returned, check it with Python’s type() function.

Fix 2: Do not loop over a boolean

Sometimes the value is meant to be a condition, not a collection.

In that case, use if, not for.

Wrong

is_logged_in = True

for item in is_logged_in:
    print(item)

Correct

is_logged_in = True

if is_logged_in:
    print("The user is logged in.")

Output:

The user is logged in.

Use if value: when you want to test whether something is True or False.

Do not treat condition results like lists or strings.

Fix 3: Debug the variable before using it

If the error is confusing, inspect the variable before the line that fails.

Useful debug checks:

print(value)
print(type(value))
print(repr(value))
print(isinstance(value, bool))

Example

value = 5 > 2

print(value)
print(type(value))
print(repr(value))
print(isinstance(value, bool))

Output:

True
<class 'bool'>
True
True

This quickly shows that value is a boolean, not an iterable.

If you need a step-by-step process, see the beginner guide to debugging Python code.

Common real-world causes

Here are common patterns that cause this error.

1. Looping over True or False directly

value = False

for item in value:
    print(item)

2. Using a comparison result in a for loop

x = 20

for item in x > 10:
    print(item)

x > 10 evaluates to True, so the loop fails.

3. A function returns bool, but the code expects a list

def is_valid():
    return True

result = is_valid()

for item in result:
    print(item)

The function returns one boolean value, not a collection.

4. A variable was overwritten with a boolean

items = ["a", "b", "c"]
items = len(items) > 0   # items is now True

for item in items:
    print(item)

This is a very common mistake. Use clear variable names so one variable does not change meaning.

5. Using in with a boolean on the right side

value = "a"
container = True

print(value in container)

This also raises:

TypeError: argument of type 'bool' is not iterable

The right side of in must be something iterable, like a string, list, tuple, set, or dictionary.

6. Passing a bool into a function that expects an iterable

value = True

print(list(value))

This raises the same error because list() expects something iterable.

Similar problems can happen with tuple() and some other functions.

How to prevent this error

A few habits make this error much less likely:

  • Use clear boolean names like is_valid, has_items, or found
  • Use plural names like items, names, or numbers for collections
  • Check function return values carefully
  • Add small debug prints when a variable’s value is unclear
  • Avoid reusing the same variable name for different kinds of data

Better naming example

items = ["apple", "banana"]
has_items = len(items) > 0

if has_items:
    for item in items:
        print(item)

This is easier to read and avoids mixing up a boolean with a collection.

You may also run into similar errors:

These errors have the same general cause: Python expected one kind of value, but got a different one.

FAQ

Why is bool not iterable in Python?

Because a boolean is just one value, True or False. It is not a collection of items.

Can I convert a bool to a list?

Not directly in a meaningful way. Usually the real fix is to use the correct iterable value instead of the boolean.

Why did my variable become a bool?

It may have been set by:

  • a comparison such as x > 10
  • a validation function
  • an accidental reassignment

Use print(value) and print(type(value)) to check.

Should I use if instead of for?

Yes, if the value is meant to be a condition rather than a group of items.

See also