关于属性在内存中的存储:不管是对象还是类,他们的属性都存储在他们自带的属性__dict__中,以字典的形式保留下来。对于类的__dict__是只读模式,不可进行修改,而对于对象的__dict__,是可以进行修改的。
对象:
class Money:
pass
one.Money()
one.age=19
one.height=180
print(one.__dict__)#将会把对象属性以字典的形式打印出来
one.__dict__[height]=190 #修改对象属性的值
类:
class Money:
age=180
height=180
print(Money.__dict__) #打印出Money的所有属性(以字典的形式)
Money.__dict__[age]=20 #报错:类对象的__dict__是只读模式的
print(Money.__dict__)