Python static Method

python static method: a static method used to return a function that does not force the passing of arguments, declaring a static method as follows.

class C(object):
    def f(arg1, arg2, ...):

The above example declares the staticmethod f so that it can be instantiated using C().f(), or of course it can be called without instantiating the method C.f()

Related course: Complete Python Programming Course & Exercises


The grammar is

def f(a,b,c):

Return value:


The following example shows how to use the staticmethod() function

class B(object):
    def f():
        print('Hello World!');

# staticmethod without instantiating
cobj = B()
cobj.f() # can also be called after instantiation


Hello World!

This is where the staticmethod() function was learned.