class Foo: def __getitem__(self, item): print('getitem',item) return self.__dict__[item] def __setitem__(self, key, value): print('setitem') self.__dict__[key]=value def __delitem__(self, key): print('delitem') self.__dict__.pop(key) f1= Foo() print(f1.__dict__) f1['name']='egon' f1['age']=19 print('=====>',f1.__dict__)