python 那些‘魔法函数’

#__setattr__ __delattr__
class
Test: def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) def __delattr__(self, item): print(item) def __setattr__(self, key, value): print(key, value) t = Test(name='zhangsan', heigth=180)

猜你喜欢

转载自www.cnblogs.com/alplf123/p/8983888.html