面向对象-静态方法、类方法、实例方法之综合案例

class Game(object): top_score=0 def __init__(self,player_name): self.player_name=player_name @staticmethod def show_help(): print("帮助信息:让植物战胜僵尸,守住家园") @classmethod def show_top_score(cls): print("历史记录 %d 分"%cls.top_score) def start_game(self): print("%s 开始游戏啦"%self.player_name) #1.使用静态方法查询帮助信息 Game.show_help() #2.使用类方法查询历史记录 Game.show_top_score() #3.创建游戏对象 game=Game("玩家A") game.start_game()


浙公网安备 33010602011771号