I am looking the following python3 code:
class MyClass(MyAbstractClass):
:
def my_fun1(self, input1):
:
return result
Then at other part of the codes, MyClass is used like:
output = MyClass().my_fun1(input1)
I am wondering does MyClass().my_fun1(input1) instantiate an object of MyClass implicitly? Or MyClass() here is treated as a utility function class? If it is a utility function, why bother put it within a class? Or is it a static class? but it the my_fun1 isn't marked as a static function?
Sorry I am coming from C++/Java background, so this is a bit strange to me ...
Thanks a lot!
Calling
MyClass().my_fun1(input1)instantiats an object of MyClass first (sinceMyClass()calls the constructor) and then callsmy_fun1function. In Python, there is no static class, but we do have static method and class method. You could find many good references for these concepts such as HERE and HERE.If you define a static method in
MyClass, you will need to call it in the following manner:Note that there is no
()afterMyClass, meaning you are not creating an object (instance).