Python staticmethod() Function
Python staticmethod returns a static method of a function.
This method does not require parameters to be passed, as in the following declaration of a static method:
class C(object):
@staticmethod
def f(arg1, arg2, ...):
...
The above example declares a static method f, so it can be used through an instance as C().f(). Of course, it can also be called without instantiating as C.f().
Function syntax
staticmethod(function)
Parameter Description:
- None
Example
#!/usr/bin/python
-- coding: UTF-8 --
class
C
(
object
)
: @
staticmethod
def
f
(
)
:
(
'
runoob
'
)
;
C
.
f
(
)
;
A static method needs no instantiation
cobj
=
C
(
)
cobj
.
f
(
)
It can also be called after instantiation
The output of the above example is:
runoob
runoob
Python built-in function