类属性,类方法,静态方法小例子

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XUEER88888888888888/article/details/85270547
class game(object):

    top_score = 0

    def __init__(self,play_name):
        self.play_name = play_name


    @staticmethod
    def show_help():
        print("这个游戏这样这样玩。。")

    @classmethod
    def show_top_score(cls):
        print("历史最高纪录 %d" %cls.top_score)

    def start_game(self):
        print("%s开始游戏啦!!" %self.play_name)


game.show_help()
game.show_top_score()

wx = game("雪儿")
wx.start_game()





在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/XUEER88888888888888/article/details/85270547