python类方法
学得有点不扎实,复习一下。类方法,实例方法,静态方法。
cls代表了类型,可以使用它继续构造新的对象或者使用静态变量。
静态函数就是跟类没半毛钱关系的,完全独立了。
记住,三种方法都可以通过实例或者类名去调用
class timemode:
@staticmethod
def showtime():
print("nice")
def showthis(self):
print("sjho")
@classmethod
def s(cls):
print(type(cls))
return cls()
timemode.showtime()
a = timemode()
timemode.showthis(a)
timemode.s()
a.s().showthis()
# nice
# sjho
# <class 'type'>
# <class 'type'>
# sjho