為什么最后會打印出None
class ?Programer(object):
? ?hobby = "Play computer"
? ?def __init__(self,name,age,weight):
? ? ? ?self.name = name
? ? ? ?self._age = age
? ? ? ?self.__weight = weight
? ?@classmethod
? ?def ?get_hobby(cls):
? ? ? ?return cls.hobby
? ?@property
? ?def get_weight(self):
? ? ? ?return self.__weight
? ?def self_introduction(self):
? ? ? ?print "My name is %s \n I'm %d years old"%(self.name,self._age)
if __name__ == "__main__":
? ?programer = Programer("Albert",25,80)
? ?print dir(programer)
? ?print programer.__dict__
? ?print Programer.get_hobby()
? ?print programer.get_weight
? ?print programer.self_introduction()
2020-01-28
簡單的來說,最后一個結(jié)果None是 self_introduction()方法的返回值,也就是未顯式的return 語句。
2019-07-16
就好比你打印introduction時打印兩次 當(dāng)然有問題 去掉下面的print或者將上面的print改為return
2018-06-10
去掉print
2017-06-09
很簡單 因為最后一個函數(shù)沒有返回值 ?樓主你的基礎(chǔ)太差了 ?多看看基礎(chǔ)吧