>> s = "hello...,Python中判断变量是否可迭代">

Python中判断变量是否可迭代

Python中判断变量是否可迭代


发布日期: 2017-11-04 更新日期: 2017-11-04 编辑:bukun 浏览次数: 5594

摘要: 方法一: 适用于Python2和Python3: >>> from collections import Iterable >>> isinstance("str", Iterable) True 方法二: 只适用于Python3 >>> s = "hello...

方法一: 适用于Python2和Python3:

>>> from collections import Iterable
>>> isinstance("str", Iterable)
True

方法二:

只适用于Python3

>>> s = "hello world"
>>> hasattr(s, "__iter__")

关注公众号
获取免费资源

随机推荐