标签:nbsp 操作 style code val rgs elf value 实验
class MyClass(object): def __call__(self, *args, **kwargs): print(66666) def __setattr__(self, key, value): print(‘setattr>>‘, key, value) def __getattr__(self, item): print(‘getattr>>‘, item) def __setitem__(self, key, value): print(‘setitem>>‘, key, value) def __getitem__(self, item): print(‘getitem>>‘, item, "item") def func(): return 123 a = MyClass() a.name = "ZWQ" # setattr>> name ZWQ a.mynameissetattr # getattr>> mynameissetattr # 点操作,设置与获取调用的是__setattr__, __getatter__方法 a["name"] = "ZWQ" # setitem>> name ZWQ a["my name is name"] #getitem>> my name is name item # []是操作元素,调用__item__方法
标签:nbsp 操作 style code val rgs elf value 实验
原文地址:https://www.cnblogs.com/zwq-/p/10447179.html