pyton 类(4) 静态方法



class Cat():

tag = ' 猫科动物 '

def __init__(self, name):
self.name = name
@staticmethod
def breah():
print('需要呼吸空气')

@classmethod
def show_info(cls, name):
# print("类的属性:{0},实例的属性:{1}".format(cls.tag, cls.name))
return cls(name)


def show_info2(self):
print("类的属性:{0},实例的属性:{1}".format(self.tag,self.name))

if __name__ == '__main__':
# 可以通过 类 和实例 进行调用
# Cat.breah()
#
# cat = Cat('小黑')
# cat.breah()
#
# cat.show_info2()

cat2 = Cat.show_info('小黄')
cat2.show_info2()
原文地址:https://www.cnblogs.com/ericblog1992/p/11288444.html