如何在Python类中获取函数的返回值
以下代码展示了如何在Python类中获取函数的返回值。
示例
class Score():
def __init__(self):
self.score = 0
self.num_enemies = 5
self.num_lives = 3
def setScore(self, num):
self.score = num
def getScore(self):
return self.score
def getEnemies(self):
return self.num_enemies
def getLives(self):
return self.num_lives
s = Score()
s.setScore(9)
print s.getScore()
print s.getEnemies()
print s.getLives()
输出
9
5
3