Search⌘ K
AI Features

Built-in Decorators

Explore Python's built-in decorators to understand how classmethod and staticmethod allow calling functions through classes or instances. Discover how the property decorator turns class methods into attributes, enabling read-only access or controlled setting. This lesson helps you learn to use these decorators to write cleaner, more flexible class code.

Python comes with several built-in decorators. The big three are:

  • @classmethod
  • @staticmethod
  • @property

There are also decorators in various parts of Python’s standard library. One example would be functools.wraps. We will be limiting our scope to the three above though.

@classmethod and @staticmethod

I have never actually used these myself, so I did a fair bit of research. The <*@classmethod>* decorator can be called with with an instance of a class or directly by the class itself as its first argument. According to the Python documentation: It can be ...