Python Func Classmethod
# Python2.x Python classmethod Decorator
[ Python Built-in Functions](#)
* * *
## Description
The function corresponding to the **classmethod** decorator does not need to be instantiated and does not require a `self` parameter. However, the first parameter needs to be a `cls` parameter representing the class itself. It can be used to call class attributes, class methods, instantiate objects, etc.
## Syntax
classmethod syntax:
classmethod
## Parameters
* None.
## Return Value
Returns the class method of the function.
## Example
The following example demonstrates the usage of classmethod:
#!/usr/bin/python# -*- coding: UTF-8 -*-class A(object): bar = 1 def func1(self): print('foo') @classmethod def func2(cls): print('func2')print(cls.bar)cls().func1()# Call the foo method A.func2()# No need to instantiate
The output result is:
func2 1 foo
[ Python Built-in Functions](#)
YouTip