Home > Article > Backend Development > [python][Basic] Determine whether a variable is iterable
Method one:
Applicable to python2 and python3
>>> from collections import Iterable >>> isinstance("str", Iterable) True
Method two:
Applicable to python3
s = "hello world" hasattr(s, "__iter__")
For more articles related to [python][Basics] Determining whether a variable is iterable, please pay attention to the PHP Chinese website!