标签:__init__ exit 初始 成员 nbsp 数据 elf color war
class Foo: def __init__(self,a,b): print(‘我是第二部,初始化数据‘) self.a=a self.b=b def __call__(self, *args, **kwargs): return args,kwargs def __getitem__(self, item): return item def __setitem__(self, key, value): print(key,value) def __delitem__(self, key): print(key) def __add__(self, other): return self.a+other.b def __enter__(self): print(‘hollo‘) def __exit__(self, exc_type, exc_val, exc_tb): print(‘get out‘) def __new__(cls, *args, **kwargs): print(‘先执行的是我,创建空对象‘) return object.__new__(cls) obj=Foo(1,100) print(obj(1,2,3,lyd=1000000)) print(obj[666]) obj[666]=‘very_good‘ del obj[666] obj2=Foo(-1,-100) print(obj+obj2) with obj as f: print(‘我轻轻的走来‘) print(‘不带走一片云彩‘) ‘‘‘
标签:__init__ exit 初始 成员 nbsp 数据 elf color war
原文地址:https://www.cnblogs.com/amber-liu/p/9558066.html