PHP
·
发表于 5年以前
·
阅读量:8410
>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> getattr(xiaoming,'name')# 判断 xiaoming有无 name属性
'xiaoming'
>>> hasattr(xiaoming,'name')
True
>>> hasattr(xiaoming,'address')
False