Web
Opt
tools
Private Attributes Config
Class Name
Private Attribute Name
Will be prefixed with __ (double underscore)
Operation
Create Object
Get Private Attribute
Set Private Attribute
Call Method
Test Direct Access
Initial Value
Custom Method Name
Optional: Method to access private attribute
Run Visualization
Console Output
>
Private Attributes Visualization
Current Configuration:
Class:
MyClass
Private Attribute:
__data
Operation:
create
Initial Value:
100
Custom Method:
get_data
Private Attribute:
Private Attribute
__data (Name Mangling Applied)
Cannot be accessed directly from outside the class. Python automatically renames it to _MyClass__data
Access Methods:
get_data()
Getter Method
set_data(value)
Setter Method
obj.__data
Direct Access (Blocked)
Name Mangling:
Original
__data
Mangled
_MyClass__data
Python automatically renames private attributes to prevent direct access
Operation Status:
Object Created
Instance of MyClass created successfully
Code Structure:
class MyClass:
def __init__(self):
self.__data = 100
def get_data(self):
return self.__data
def set_data(self, value):
self.__data = value
def get_data(self):
return f"Private data: {self.__data}"
Encapsulation Benefits:
Data Protection:
Private attributes cannot be accessed or modified directly from outside the class
Controlled Access:
Access is only possible through defined getter and setter methods
Implementation Hiding:
Internal implementation details are hidden from external code