这两个代码将给出两个不同的输出,为什么?
class Test:
def __get__(self, instance, owner):
return 42
def __set__(self, instance, value):
pass
class A:
a = Test()
a = A()
print(a.a) // print 42
a.a = 0
print(a.a) // print 42
和
class Test:
def __get__(self, instance, owner):
return 42
def __set__(self, instance, value):
pass
class A:
pass
a = A()
a.a = Test()
print(a.a) // print <__main__.Test object at 0xb700d6cc>
a.a = 0
print(a.a) // print 0
Python 引擎中如何存储属性?