OOP-魔法函数

魔法函数

- 操作相关

    __new__     第一个调用一般不需要使用

    __init__       构造函数

    __call__       对象当函数使用的时候触发

    __str__        当对像当字符串用的是时候触发

- 描述符

    __set__    

    __get__

    __delete__

- 属性操作相关

    __getattr__    访问不存在的属性时触发

    __setattr__     对成员属性进行设置的时候触发(使用super否则无限死循环)

        

def __setattr__(self,name,value):
    super().__setattr__(name,value)


猜你喜欢

转载自blog.csdn.net/IF_Albert/article/details/80789278
今日推荐