[python][Basic] Determine whether a variable is iterable

高洛峰
Release: 2017-02-18 10:32:09
Original
1350 people have browsed it

Method one:

Applicable to python2 and python3

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

Method two:

Applicable to python3

s = "hello world"
hasattr(s, "__iter__")
Copy after login


For more articles related to [python][Basics] Determining whether a variable is iterable, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!