Use of isinstance() can overwrite type

This question already has an answer here:

  • What are metaclasses in Python? 14 answers

  • I think your confusion lies in the fact that type(dict) != dict . Lets discard your example entirely except for the last two lines, which I will use interactive python to present.

    >>> type(dict)
    <type 'type'>
    >>> type(dict())
    <type 'dict'>
    

    This is because dict is not a dictionary, but the type of dictionaries. dict() or {} (or {1:2, ...} ) are instances of dictionaries. These instances have type of dict , and satisfy isinstance(___, dict) .

    链接地址: http://www.djcxy.com/p/6990.html

    上一篇: 如何在Python中创建常量?

    下一篇: 使用isinstance()可以覆盖类型