getters & setters in Python OOP

Anna Ikoki
1 min readFeb 7, 2023

In OOP (Python), you have a class that defines data attributes (properties), and methods that work on the attributes.

Among others, there are 2 methods that directly work on the properties to avoid directly manipulating the data attributes outside the class: getters and setters.

Getters are methods that grab data from the data attributes. Here you use return

Setters are methods that change data in the data attributes (instance variables). Hence, they don’t return anything, and instead, take an extraparameter

--

--