根据Python docs:
如果为派生类调用类方法,则派生类对象将作为隐式第一个参数传递。
因此我们可以得出结论,我们不需要使用类方法function创建对象。但是我不知道为什么PyCharm会给我这个警告,而它却可以毫无问题地执行代码。
这是代码:
class Fruit:
def sayhi(self):
print("Hi, I'm a fruit")
Fruit.sayhi = classmethod(Fruit.sayhi)
Fruit.sayhi()enter code here
这是警告
参数未填写