代码实验展示:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
>>>
>>> class EmptyClass4CXQ:
pass
>>>
>>> ec = EmptyClass4CXQ()
>>> ec.__dict__
{}
>>> print(ec.__dict__)
{}
>>>
>>> ec.name = "名字"
>>> ec.name
'名字'
>>>
>>>
>>> ec.__dict__
{'name': '名字'}
>>> print(ec.__dict__)
{'name': '名字'}
>>>
>>> ec.age
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
ec.age
AttributeError: 'EmptyClass4CXQ' object has no attribute 'age'
>>> ec.age = 18
>>> ec.age
18
>>> ec.__dict__
{'name': '名字', 'age': 18}
>>> print(ec.__dict__)
{'name': '名字', 'age': 18}
>>> ec.age = 19
>>> ec.age
19
>>> ec.name = "mingzi"
>>> ec.name
'mingzi'
>>>
>>> ec.__dict__
{'name': 'mingzi', 'age': 19}
>>> print(ec.__dict__)
{'name': 'mingzi', 'age': 19}
>>>
>>>