[python][基础]判断变量是否可迭代
来源:动视网
责编:小采
时间:2020-11-27 14:26:42
[python][基础]判断变量是否可迭代
[python][基础]判断变量是否可迭代:方法一:适用于python2和python3>>> from collections import Iterable >>> isinstance("str", Iterable) True方法二:适用于python3s = "hello world" hasattr(s,
导读[python][基础]判断变量是否可迭代:方法一:适用于python2和python3>>> from collections import Iterable >>> isinstance("str", Iterable) True方法二:适用于python3s = "hello world" hasattr(s,

方法一:
适用于python2和python3
>>> from collections import Iterable
>>> isinstance("str", Iterable)
True方法二:
适用于python3
s = "hello world"
hasattr(s, "__iter__")
更多[python][基础]判断变量是否可迭代相关文章请关注PHP中文网!
[python][基础]判断变量是否可迭代
[python][基础]判断变量是否可迭代:方法一:适用于python2和python3>>> from collections import Iterable >>> isinstance("str", Iterable) True方法二:适用于python3s = "hello world" hasattr(s,