Search code examples
pythonpropertiesdecorator

Why would someone use @property if no setter or deleter are defined?


In python code I often see the use of @property.

If I understand correctly, with the property function a getter setter and deleter can be defined.

Why would one use @property if the setter and deleter are not defined (@x.setter, @x.deleter)? Isn't this the same as not using @property at all?


Solution

  • It creates an API that does not allow a value to be set. This is similar in other languages to a constant.