0
Please explain to me what static methods are?
I couldn't understand what static methods are. Can someone please give an explanation with an example
2 Answers
+ 1
the static method is similar to a class & can be passed with arguments but only can be invoked with argument that is already declared no new arguments at runtime are accepted.
0
If you apply static keyword with any method, it is known as static method. A static method belongs to the class rather than object of a class. A static method invoked without the need for creating an instance of a class. static method can access static data member and can change the value of it.
Yep, using the staticmethod decorator
class MyClass(object):
@staticmethod
def the_static_method(x):
print x
MyClass.the_static_method(2)
# outputs 2
Note that some code might use the old method of defining a static method, using staticmethod as a function rather than a decorator. This should only be used if you have to support ancient versions of Python (2.2 and 2.3)