class Person:
money=None
def __init__(self, name, age):
self.name = name
self.age = age
p = Person('Alice', 20)
print(p.__dict__) # 输出:{'name': 'Alice', 'age': 20}
print(Person.__dict__) # 输出: {'__module__': '__main__', 'money': None, '__init__': <function Person.__init__ at 0x0000028518D2DD38>, '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}
__dict__的理解:一个字典对象,保存对象的属性及其对应的值.
类的实例__dict__只输出了自身的属性和值;但是能访问类的属性和值,以及父类的属性和值(必须的,要不然怎么调用__dict__?)
类的__dict__输出了自身的属性和值+父类的属性和值,但不包含类的实例的属性和值,且不可访问类的实例的属性和值.