Properties are a special kind of attribute. Basically, when Python encounters the following code:
spam = SomeObject()
print(spam.eggs)
it looks up eggs
in spam
, and then examines eggs
to see if it has a __get__
, __set__
, or __delete__
method — if it does, it’s a property. If it is a property, instead of just returning the eggs
object (as it would for any other attribute) it will call the __get__
method (since we were doing lookup) and return whatever that method returns.
More information about Python’s data model and descriptors.