class Game(object):
top_score = 0 #类属性
def __init__(self,player_name): #初始化类属性
self.player_name = player_name
Game.top_score += 20
@classmethod #类方法
def show_top_score(cls):
print("the history top score is ",cls.top_score)
@staticmethod #静态方法
def show_help():
print("fight man back!")
print(Game.top_score) #类属性
Game.show_top_score() #类方法
Game.show_help() #静态方法
1、python类记录(类属性方法、对象属性方法,静态属性的定义及访问)
最新推荐文章于 2023-02-14 20:38:01 发布