求大神解釋啊?
class Person(object):
? ? def __init__(self,name,gender,birth,**kw):
? ? ? ? self.name = name
? ? ? ? self.gender = gender
? ? ? ? self.birth = birth
? ? ? ? self.__dict__.update(kw)##這一句是啥意思?。?/strong>
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2016-07-18
你在每行前后加入打印self.__dict__的值,就會發現其實他是把接收到的值加入到字典中。
通過字典調用值,xiaoming.job