标签:pre eth 对象 实例 self person 装饰器 int ssm
class Person:
# 实例方法
def chi(self):
print("人会吃")
@classmethod # 装饰器, 此时这个方法是一个类方法
def he(cls): # 此时接收到的cls是类名
# print(cls)
print("人会喝")
# 用对象访问
# p = Person()
# p.he() # 在调用类方法的时候. 默认的把类名传递给类方法
# print(Person)
# 类方法一般用类名去访问
Person.he() # 类方法
标签:pre eth 对象 实例 self person 装饰器 int ssm
原文地址:https://www.cnblogs.com/work14/p/10145426.html