Explain the Python Oops Encapsulation with example.
Explain the Python Oops Encapsulation with example.
299
27-Oct-2025
Updated on 03-Nov-2025
ICSM Computer
02-Nov-2025It also helps in restricting direct access to the internal state of an object — protecting data from unintended modification.
In Python, encapsulation is implemented using:
_(single underscore), meant for internal use.__(double underscore), not accessible directly from outside the class.Example of Encapsulation
Output
Why Encapsulation is Important
Accessing Private Variables (Name Mangling)
Even though private variables are not directly accessible, Python internally renames them: