Tutorial 6: OOPs in Python — Encapsulation-Protected attributes
Missed previous lecture ?? — Click here
In this tutorial we will cover following topics :
Protected attribute
protected attributes are preceded by single underscore.

As we can see protected attributes can be accessed and modified outside class. To make them protected property decorator is used.
Property decorator
Let’s see Property decorator at work using example given below:


Using property decorator, modifying the attribute raises AttributeError and thus it is protected from being modified outside class.
Property setter
To be able to modify the protected attribute we use property setter as given below :

Using property setter now protected attribute can be modified.
Congratulations !!
You have completed fifth tutorial. Take a deep breathe and move to the next tutorial.