How does the @property decorator work in Python?

后端 未结 13 2067
闹比i
闹比i 2020-11-21 04:49

I would like to understand how the built-in function property works. What confuses me is that property can also be used as a decorator, but it only

13条回答
  •  后悔当初
    2020-11-21 05:26

    A property can be declared in two ways.

    • Creating the getter, setter methods for an attribute and then passing these as argument to property function
    • Using the @property decorator.

    You can have a look at few examples I have written about properties in python.

提交回复
热议问题