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

Python中判断变量是否可迭代

Python中判断变量是否可迭代


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

标签:

摘要: 方法一: 适用于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__")

关注公众号
获取免费资源

随机推荐


Copyright © Since 2014. 开源地理空间基金会中文分会 吉ICP备05002032号

Powered by TorCMS

OSGeo 中国中心 邮件列表

问题讨论 : 要订阅或者退订列表,请点击 订阅

发言 : 请写信给: osgeo-china@lists.osgeo.org