Python iterable function

Python iterable refers to a sequence which can be loop through. For example, lists, strings are iterables. iter() function can check whether a variable is an iterable or not.

>>> x = 'abc'
>>> iter(x)

To be safe, let's add exception handling:
>>> x = 3
>>> try:
... y = iter(x)
... except:
... print(y, " is not an iterable")
...
3 is not a iterable


















endmemo.com © 2024  | Terms of Use | Privacy | Home