How does one check if a Python object supports iteration, a.k.a an iterable object (see definition

Ideally I would like function similar to isiterable(p_object) returning True or False (modelled after isinstance(p_object, type)).

You can check for this using isinstance and collections.Iterable

>>> from import Iterable # for python >= 3.6
>>> l = [1, 2, 3, 4]
>>> isinstance(l, Iterable)

Note: Using or importing the ABCs from ‘collections’ instead of from ‘’ is deprecated since Python 3.3, and in 3.9 it will stop working.

Try this code

def isiterable(p_object):
        it = iter(p_object)
    except TypeError: 
        return False
    return True

You don’t “check”. You assume.

   for var in some_possibly_iterable_object:
       # the real work.
except TypeError:
   # some_possibly_iterable_object was not actually iterable
   # some other real work for non-iterable objects.

It’s easier to ask forgiveness than to ask permission.