zoukankan      html  css  js  c++  java
  • isinstance方法判断可迭代和迭代器

    from collections import Iterable
    print(isinstance([],Iterable))
    print(isinstance( {}, Iterable))
    print(isinstance( (), Iterable))
    print(isinstance( 'abc', Iterable))
    print(isinstance( '100', Iterable))
    print(isinstance((x for x in range(10) ), Iterable))
    
    
    '''
    True
    D:/见解/Python/Python代码/vacation/python高级/使用isinstance判断是否可以迭代.py:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
    True
      from collections import Iterable
    True
    True
    True
    True
    '''

    from collections import Iterator
    print(isinstance( [ ], Iterator))
    print(isinstance(  'abc', Iterator))
    print(isinstance(()  , Iterator))
    print(isinstance( {} , Iterator))
    print(isinstance(  123, Iterator))
    print(isinstance(  5+2j, Iterator))
    print(isinstance( (x for x in range(10)) , Iterator))
    # 生成器可以是迭代器
    
    
    '''
    False
    D:/见解/Python/Python代码/vacation/python高级/使用isinstance判断是否是迭代器.py:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
    False
      from collections import Iterator
    False
    False
    False
    False
    True
    '''

    2020-05-08

  • 相关阅读:
    数据结构(二)(三)栈和队列
    数据结构(一)线性表
    中信卡笔试代码
    Jenkins搭建-简单使用
    python 生成指定两个ip间的所有ip
    形象理解 什么是磁盘碎片
    形象理解软件位宽 32位和64位的区别
    看板娘>_
    Win10一张网卡设置多个ip地址
    VMware ubuntu安装tools灰色?
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12846908.html
Copyright © 2011-2022 走看看