python的staticmethod

staticmethod函数功能就是将一个方法定义成类的静态方法,正确的方法是使用 @staticmethod装饰器,这样在实例对象调用的时候,不会把实例对象本身传入静态方法的第一个参数了

类似于下面,不会用到实例本身的情况:

@staticmethod
def getStr(result):
if type(result) == tuple:
if type(result[0]) == tuple:
return result[0][0]
else:
return result[0]
posted @ 2019-11-08 13:45  孤独的羊  阅读(217)  评论(0编辑  收藏  举报