class A(object): def __setattr__(self, key, value): self.__dict__[key] = value def __getattr__(self, name): return "xxx" #实例化. obj = A() #1. 调用getattr方法 返回结果:xxx print(obj.namd22e ) #2. 调用getattr方法,返回结果:xxx print(obj.dd) #3. 打印内置属性,为空.{} print(obj.__dict__) #4. 给属性赋值 name 为key , helleworld 为值value. obj.name = "helloworld" #5. 打印内置属性,存在一个{"name":"helleworld"} print(obj.__dict__) #6. 打印name属性,结果为 helloworld print(obj.name)