Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python3直接从类名调用函数。效用函数?静态功能?或者隐式实例化一个对象_Python 3.x_Singleton_Static Methods_Utility Method - Fatal编程技术网

Python 3.x Python3直接从类名调用函数。效用函数?静态功能?或者隐式实例化一个对象

Python 3.x Python3直接从类名调用函数。效用函数?静态功能?或者隐式实例化一个对象,python-3.x,singleton,static-methods,utility-method,Python 3.x,Singleton,Static Methods,Utility Method,我正在查找以下python3代码: class MyClass(MyAbstractClass): : def my_fun1(self, input1): : return result 然后在代码的其他部分使用MyClass,如下所示: output = MyClass().my_fun1(input1) 我想知道MyClass().my_fun1(input1)是否隐式实例化MyClass的对象?或者这里的MyClass()被视为一

我正在查找以下python3代码:

class MyClass(MyAbstractClass):
      :
    def my_fun1(self, input1):
         :
        return result
然后在代码的其他部分使用MyClass,如下所示:

output = MyClass().my_fun1(input1)
我想知道
MyClass().my_fun1(input1)
是否隐式实例化MyClass的对象?或者这里的MyClass()被视为一个实用函数类?如果它是一个实用函数,为什么还要麻烦把它放在一个类中呢?还是一个静态类?但是
my_fun1
是否没有标记为静态函数

对不起,我来自C++/Java背景,所以这对我来说有点奇怪

非常感谢

调用
MyClass()。myu fun1(input1)
首先实例化MyClass的对象(因为
MyClass()
调用构造函数),然后调用
myu fun1
函数。 在Python中,没有静态类,但我们有静态方法和类方法。对于这些概念,您可以找到许多很好的参考资料,例如和

如果在
MyClass
中定义静态方法,则需要按以下方式调用它:

output=MyClass.myu静态方法(input1)

请注意,在
MyClass
之后没有
()
,这意味着您没有创建对象(实例)。

您好,已经两天了,如果您觉得我的答案有帮助,请接受好吗?