Adding Behaviors to Class Data With Properties

Learn and practice how we can add behaviors to our classes in Python.

Until now, we’ve focused on the separation of behavior and data. This is very important in object-oriented programming, but we’re about to see that, in Python, the distinction is uncannily blurry. Python is very good at blurring distinctions; it doesn’t exactly help us to think outside the box. Rather, it teaches us to stop thinking about the box.

Getter and setter methods

Before we get into the details, let’s discuss some bad object-oriented design principles. Many object-oriented developers teach us never to access attributes directly. They insist that we write attribute access like this:

Get hands-on with 1200+ tech skills courses.