Python staticmethod() Function

Python 内置函数Python Built-in Functions

python staticmethod returns a static method of the function.

This method does not require passing parameters; declare a static method as follows:

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

The above example declares a static methodf, thus enabling instantiated useC().f(), and of course you can also call this method without instantiatingC.f()。

Function Syntax

staticmethod(function)

Parameter description:

  • None

Example

#!/usr/bin/python # -*- coding: UTF-8 -*- class C(object): @staticmethod def f(): print('example'); C.f(); # Static method does not need instantiation cobj = C() cobj.f() # It can also be called after instantiation

The output of the above example is:

example
example

Python 内置函数Python Built-in Functions

Other Extensions