Search⌘ K
AI Features

Properties in Detail

Explore the use of Python’s property() function to control attribute access in object-oriented programming. Understand how to define getters, setters, and optional deleters for attributes, and how to include documentation for properties. This lesson helps you implement clean, maintainable access to internal state in Python classes.

We'll cover the following...

The property() function

Think of the property function as returning an object that proxies any requests to get or set the attribute value through the method names we have specified. The property() built-in is like a constructor for such an object, and that object is set as the public-facing member for the given attribute.

This property() constructor can actually accept two additional arguments, a delete function and a docstring for the property. The delete function is rarely supplied in practice, but it can be useful ...