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