isinstance / type / issubclass usage, reflection (hasattr, getattr, setattr, delattr)

6.23 self-summary

Object-oriented high-order

1.isinstance/type/issubclass

1.type

Class display object, but it will not show his parent

2.isinstance

Class objects displayed will also go to the parent object, object fill parameter, the isinstance class (object class) if the object belongs to the latter category will be reported Ture, contrary False

3.issubclass

But his fill and isinstance similar argument is class and class

4. Summary

Is: type (objects) are not considered to be a sub-class of the parent class type; isinstance (object class) will be considered the father of the child class is a class type.

2.反射(hasattr,getattr,setattr,delattr)

  • It is reflected to the operation by the object class or string property

  • Essentially reflected in the use of built-in functions, wherein the reflector has four built-in functions:

    1. hasattr:判断一个方法是否存在与这个类中
    2. getattr:根据字符串去获取obj对象里的对应的方法的内存地址,加"()"括号即可执行
    3. setattr:通过setattr将外部的一个函数绑定到实例中
    4. delattr:删除一个实例或者类中的方法

Lkhsattr

Usage: print (hasattr (object, method, or characteristic of the object),) must be behind the content format string, returns True if any, does not return False

2.getattr

Usage: print (getattr (object, method, or characteristic of the object)), the contents must be some later, the contents of which returns a string corresponding to the format, content must be behind the object

3.setattr

Usage: setattr (YwY, ', or the characteristics of the subject method, the corresponding value), or a method without this feature will be added, if the replacement

4.delattr

Usage: The method delattr (YwY, ', object methods or features), delete objects or features have

Guess you like

Origin www.cnblogs.com/pythonywy/p/11074457.html