Why is it recommended to use isinstance instead of type for instance checking in python?
阿神
阿神 2017-05-24 11:35:09
0
2
804

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.

阿神
阿神

闭关修行中......

reply all (2)
洪涛

When the comparison object is a subclass instance and a parent class,isinstance会认为相等,typeis not equal.

is equivalent toisinstancetype多了个检查继承的功能,所以更愿意选择isinstance.

    世界只因有你
    /q/1010000000127305 看这个,更详细一点
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!