http://codingpy.com/article/p...
Example check:
Use isinstance(a, C) instead of type(a) is C`. But generally avoid doing instance checking. It is recommended to check the characteristics of the instance.
PHP中文网2017-05-24 11:37:09
When the comparison object is a subclass instance and a parent class, isinstance
会认为相等,type
is not equal.
is equivalent to isinstance
比 type
多了个检查继承的功能,所以更愿意选择 isinstance
.