How the @property decorator work in Python?
How the @property decorator work in Python?
556
11-Apr-2023
Aryan Kumar
19-Apr-2023In Python, the @property decorator is used to define a method as a getter method for a class attribute. It allows you to access the attribute using the dot notation as if it were a regular property, while also allowing you to add custom logic to the attribute's getter method.
Here's an example of how the @property decorator works:
Krishnapriya Rajeev
13-Apr-2023In Python, a decorator encloses a function, adds a number of features, and then returns the result.
The @property decorator in Python is used to define a method as a read-only attribute of a class. It allows us to access a method like an attribute, without the need to invoke it like a function.
Here's an example to illustrate the usage of @property decorator:
Here's how the @property decorator works: