wangjianweiwei / blog

点滴记录
1 stars 0 forks source link

python class魔术方法总结 #17

Open wangjianweiwei opened 4 years ago

wangjianweiwei commented 4 years ago

__doc__

image 红框里的就是doc方法的值

__dict__

对象的属性都在dict

class A:

    def __init__(self, name, age):
        self.name = name
        self.age = age

if __name__ == '__main__':
    a = A(name="toy", age=30)
    print(a.__dict__)
    # {'name': 'toy', 'age': 30}

__slots__

__module__

__annotations__

__init__

__new__

__hash__

__len__

__eq__

__ne__

__str__

__repr__

__format__

__getattribute__

__delattr__

__sizeof__

__reduce__

__reduce_ex__

__dir__

__get__

__set__

__del__

__getattr__

__setattr__

__delattr__

__getitem__

__setitem__

__delitem__

__enter__

__exit__

__next__

__iter__