本文实例讲述了Python实现动态添加属性和方法操作。分享给大家供大家参考,具体如下:
运行结果:
ff 28
female
None
155
run with 30 speed
run with 4 m/s
run with 5 m/s
eat---
eat---
Traceback (most recent call last):
File "/home/python/Desktop/test/12_动态语言.py", line 41, in <module>
print(p1.name, p1.sex)
AttributeError: 'Person' object has no attribute 'name'
希望本文所述对大家Python程序设计有所帮助。
新闻热点
疑难解答