Built-in Functions
classmethod()
Make a method receive the class instead of an instance.
classmethod(function)
Use @classmethod above a method when the method should work with class-level information. Its first parameter conventionally has the name cls.
Parameters
| Name | Description |
|---|---|
| function | The function to wrap as a class method. |
Returns
A class method descriptor.
Try it
Run it and change it
class Temperature:
unit = "C"
@classmethod
def label(cls):
return f"Degrees {cls.unit}"
print(Temperature.label())