Protected Members
Introduction to OOP's
Class
Object
Constructor
Instance Variables
Class Variables
Instance Methods
self Keyword
Encapsulation
Public Members
Protected Members
Private Members
Inheritance
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid Inheritance
super() Function
Polymorphism
Method Overriding
Duck Typing
Abstraction
Abstract Class
Abstract Method
Class Method
Static Method
Special Methods
_str_ Method
Operator Overloading
Composition
Aggregation
Association
Method Resolution Order
Object Class
issubclass() and isinstance()
Property Decorator
Setter Method with @property
Destructor
Inner Class
Complete Mini Example
Protected Members
10. Protected Members
Python uses a single underscore prefix as a convention for protected members. This signals that the member is intended for internal or subclass use, though it is still accessible.
Syntax
self._value = 10
Example
class Parent:
def __init__(self):
self._msg = "Protected Member"
class Child(Parent):
def show(self):
print(self._msg)
c = Child()
c.show()
Output
Protected Member
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Protected Members to test your knowledge.
Browse Quizzes »