Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 576 Bytes

38.md

File metadata and controls

24 lines (19 loc) · 576 Bytes
@author jackzhenguo
@desc 
@date 2019/3/10

38 动态获取对象属性 

获取对象的属性

In [1]: class Student():
   ...:     def __init__(self,id,name):
   ...:         self.id = id
   ...:         self.name = name
   ...:     def __repr__(self):
   ...:         return 'id = '+self.id +', name = '+self.name

In [2]: xiaoming = Student(id='001',name='xiaoming')
In [3]: getattr(xiaoming,'name') # 获取xiaoming这个实例的name属性值
Out[3]: 'xiaoming'
[上一个例子](37.md) [下一个例子](39.md)