【发布时间】:2015-07-21 18:52:45
【问题描述】:
以下是测试类,其方法不接受 cls 或 self 参数,并且没有 @staticmethod 装饰器。它们像普通的静态方法一样工作,不会抱怨参数。这似乎与我对 python 方法的理解相反。 python是否会自动将非类、非实例方法视为静态方法?
>>> class Test():
... def testme(s):
... print(s)
...
>>> Test.testme('hello')
hello
>>> class Test():
... def testme():
... print('no')
...
>>> Test.testme()
no
P.S:我用的是python3.4
【问题讨论】:
标签: python python-3.x