[python][基础]判断变量是否可

发布时间:2019-10-16 17:29:49编辑:auto阅读(2361)

    方法一:

    适用于python2和python3

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

    方法二:

    适用于python3

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

关键字