类方法
class Person(object):
__country = "中国"
@classmethod
def get_country(cls):
return cls.__country
@classmethod
def set_counry(cls, new_country):
cls.__country = new_country
Person.set_counry("美国")
print(Person.get_country())
静态方法
# 格式:def 方法名(self):
# 一 实例方法 调用
# 01格式: 对象名.实例方法名()
# p = Person()
# print(p.get_name())
# 02格式: 不建议写
# Person.get_name(Person())
# 格式:@classmethod
# def 方法名(cls)
# 二 类方法 调用
# 01格式: 类名.类方法名()
# print(Person.get_country())
# 02格式: 对象名.类方法名()
# p = Person()
# print(p.get_country())
# 格式:@staticmethod
# def 方法名():
# 三 静态方法 调用
# 01格式: 类名.静态方法名()
# Person.hello_python()
# 02格式: 对象名.静态方法名()
# p = Person()
# p.hello_python()