class Student():
def __init__(self, id, name):
self.id=id
self.name=name
def __repr__(self):
return 'id='+self.id+', name='+self.name
han=Student(id="001", name="mozhaxi")
getattr(han,"name") #获取han这个实例的name属性值
out:
'mozhaxi'
网友评论