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]

猜你喜欢

转载自www.cnblogs.com/sylarwang/p/11819695.html