Use of isinstance() can overwrite type
This question already has an answer here:
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)
.
上一篇: 如何在Python中创建常量?
下一篇: 使用isinstance()可以覆盖类型