Junior — Senior
Overview of built-in decorators in Python class
livecode
Task condition
Explain how standard decorators applied to class methods work, and demonstrate their usage both through the class itself and through its instance.
class Sample:
value = 1
@classmethod
def cls_meth(cls, a):
return cls.value + a
@staticmethod
def stc_meth(a):
return a * a
@property
def prop(self):
return self.value
Sample.cls_meth(1)
Sample.stc_meth(1)
Sample().prop
s = Sample()
s.cls_meth(1)
s.stc_meth(1)
s.prop
(Note: The original code had an error in the property method definition; it should not have parameters other than self.)