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学习笔记 文章被收录于专栏

自学笔记记录

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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