python数据分析基础29-对象是否有这个属性
2020-04-16 本文已影响0人
Zhigang_Han
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="xiaoming")
hasattr(han,"name")
hasattr(han,"address")
out:
True
False