Python 101 : Accessing private attributes using the "property()" function


 To be able to access the attributes of a class while keeping these attributes safe from any unintended modification, we can to use properties.

One way to use properties is to "declare" the setter and getter functions within the class using the "property()" function as below:


We can also access these properties directly as we see in the below example:


Comments

Leave as a comment:

Archive