python课后52求助
class A:def __init__(self, a, b, c):
self.x = a + b + c
a = A(1,2,3)
b = getattr(a, 'x')
setattr(a, 'x', b+1)
print(a.x)
为什么最后打印出来是7 就是简单的更改了a.x的值
class A:
def __init__(self, a, b, c):
self.x = a + b + c
a = A(1,2,3)
b = getattr(a, 'x') #返回a.x
setattr(a, 'x', b+1) #将a.x的值重新赋值为b+1
print(a.x)
页:
[1]