Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

How to Check if an Object Is Iterable in Python

Call iter(obj) to check whether Python can obtain an iterator. Catch TypeError for a Boolean result; isinstance(obj, Iterable) is not a complete runtime test.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To check whether Python can iterate over an object, call iter(obj). If Python cannot obtain an iterator, it raises TypeError; catch that exception when you need a Boolean result. This runtime test also handles objects that use Python’s legacy sequence-iteration protocol.

Use iter() for a runtime check

Python’s documentation identifies iter(obj) as the reliable way to determine whether an object is iterable. A successful call means Python obtained an iterator at that moment. If the object does not support iteration, Python raises TypeError.

def is_iterable(obj):
    try:
        iter(obj)
    except TypeError:
        return False
    return True

For example, is_iterable([1, 2, 3]) returns True, while is_iterable(42) returns False. The check obtains an iterator; it does not consume values from that iterator.

When to use collections.abc.Iterable

If you specifically want to check whether a value advertises or is registered with the Iterable interface, use isinstance():

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from collections.abc import Iterable

isinstance([1, 2, 3], Iterable)  # True

However, this is an interface classification, not a complete runtime test. The Iterable ABC recognizes classes that provide __iter__ and types registered with the ABC, but it can miss objects that support iteration through the legacy sequence protocol: defining __getitem__ to return successive items until it raises IndexError. For that reason, prefer iter(obj) when your question is whether Python can actually iterate over a particular value. The distinction is documented in the Python 3.13 collections.abc documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the check does—and does not—prove

  • It may run object code. Calling iter(obj) can invoke a custom __iter__ method or, for legacy sequence-style objects, __getitem__. It is not necessarily a side-effect-free inspection.
  • It does not guarantee a later operation will succeed. The check establishes that an iterator could be obtained at that moment; it does not prove that iteration will complete or that every value yielded will meet your needs.
  • Iterators are iterable. An iterator supports the iterable protocol and adds __next__ to produce values.
  • Asynchronous iteration is separate. iter(obj) checks ordinary iteration, not the asynchronous protocol associated with __aiter__.

Choose the check that matches your purpose

Approach Use it when Important limitation
iter(obj), catching TypeError You need to know whether Python can obtain an iterator for this value. May invoke user-defined behavior.
isinstance(obj, collections.abc.Iterable) You need to classify a value against the advertised or registered ABC interface. May not recognize legacy __getitem__-only iteration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.