Class method static method

python


class Person(object):
    kind = 'human'

    def __init__(self):
        self.x = 100

    @classmethod
    def what_is_your_kind(cls):
        return cls.kind

    @staticmethod
    def about(year):
        print('human about {}'.format(year))

print(Person.what_is_your_kind())
Person.about(1999)

Execution result


human
human about 1999

With Person.what_is_your_kind () Since it is not Person () and the object is not created, Originally it will be an error.

But, By making what_is_your_kind a class method, Not a method of the what_is_your_kind object, It becomes a method of the class and can be accessed.

Recommended Posts

Class method static method
[Python] Difference between class method and static method
parallelization of class method
parallelization of class method
Class methods and static methods
Various class methods and static methods
class
Profile within a class method
Manim's method 7
Manim's method 13
Manim's method 2
Manim's method 18
Manim's method 17
Manim's method 3
Manim's method 15
Manim's method 11
Class variables
Manim's method 16
Manim's method 20
Binary method
Manim's method 10
Manim's method 9
Class variables
Manim's method 21
Manim's method 4
Manim's method 8
Manim's method 14
Manim's method 22
Manim's method 19
Manim's method 12
Special method
Special method
Abstract class
Try using an object-oriented class in R (R6 method)