●@classmethod使用实例
#!/usr/bin/python
# -*- coding: utf-8 -*-
#@Users: LiMu
#@Files:UseClassmethod.py
#@Times: 2023/3/29
#@Software:PyCharm
class aaa(object):
def __int__(self):
pass
@classmethod
def bbb(self):
print("self")
@classmethod
def ccc(cls):
print("cls")
if __name__ == '__main__':
aaa.bbb()
aaa.ccc()
D:\Python37\python.exe E:\pythonFiles\Interfacetest\tools\notepad.py
self
cls
Process finished with exit code 0
●@staticmethod使用实例
#!/usr/bin/python
# -*- coding: utf-8 -*-
#@Users: LiMu
#@Files:UseStaticmethod.py
#@Times: 2023/3/29
#@Software:PyCharm
class aaa(object):
@staticmethod
def bbb():
print("staticmethod")
if __name__ == '__main__':
aaa.bbb()
D:\Python37\python.exe E:\pythonFiles\Interfacetest\tools\notepad.py
staticmethod
Process finished with exit code 0