Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 553 Bytes

39.md

File metadata and controls

25 lines (20 loc) · 553 Bytes
@author jackzhenguo
@desc 
@date 2019/3/10

39 对象是否有某个属性

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]: hasattr(xiaoming,'name')
Out[3]: True

In [4]: hasattr(xiaoming,'address')
Out[4]: False
[上一个例子](38.md) [下一个例子](40.md)