类方法的分类及具体使用
方法分为:
- 类方法,
- 静态方法,
- 实例方法
类方法(用装饰器)
class Person():
pass
@classmethod
def func(cls):
print(123121)
Person.func() #使用装饰器后不用引参,若不使用@classmethod,则Person.func(1)
静态方法
class Person():
pass
@staticmethod
def fol():
print(23123)
#使用方法1
Person.fol()
#使用方法2
a=Person()
a.fol()
静态方法有两种使用方法:
1.Person.fol() 用类调用
2.具体实例化
实例方法
class Person():
pass
def func(self):
print(123121)
a=Person()
a.func()