一、递归案例–计算数字累加
def sum_numbers(num):
if num == 1:
return 1
temp = sum_numbers(num-1)
return num + temp
result = sum_numbers(5)
print(result)
二、类属性、实例属性、类方法、静态方法、实例方法
class Game(object):
top_score = 0
def __init__(self, payer_name):
self.play_name = payer_name
@staticmethod
def show_help():
print("帮助信息")
@classmethod
def shoe_top_score(cls):
print("历史记录 %d" % cls.top_score)
def start_game(self):
print("%s 开始游戏" % self.play_name)
Game.show_help()
Game.shoe_top_score()
game = Game("小明")
game.start_game()