20220213类方法-静态方法-实例方法


#Game游戏类
from random import randint
class Game(object):
    
    top_score=0
    
    @staticmethod
    def show_help():
        print("This is help doc.")
    
    
    @classmethod
    def show_top_score(cla):
        print(f"The top score is {Game.top_score}!!!")
        #print(f"The top score is {Game.top_score}!!!")
        #类属性也可以用 cla. 调用
        print(f"The top score is {cla.top_score}!!!")
    
    def __init__(self,name):
        self.name=name
    
    def strat_game(self):
        a=randint(1,100)
        print(f"{self.name} score is {a}.")
        
        if a>Game.top_score:
            Game.top_score=a
            print(f"现在最高分是你!{self.name} Cons")
            return
        
        
        
    
    
a=Game("lize")
b=Game("Shipengfei")
a.show_help()
Game.show_top_score()

a.strat_game()
b.strat_game()
Game.show_top_score()
python学习笔记 文章被收录于专栏

自学笔记记录

全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务