Python OOP Encapsulation Explained 🔐 | Private, Protected & Public Variables
✅ Object-Oriented Programming Part-2: Encapsulation ✍️ 🔐 What is Encapsulation Encapsulation = protecting data inside a class. Hide internal data Control how data is accessed Prevent direct modification Real-life example. ATM machine You cannot access bank balance directly You use functions (deposit, withdraw) 🔒 Why Encapsulation is important Data security Controlled access Prevent accidental changes Cleaner code structure 📚 Public Variables (Normal Variables) Accessible from anywhere. class Student: def __init__(self): self.name = "Deepak" s = Student() print (s.name) Problem → anyone can change data. s.name = "Ankit" 🔒 Protected Variables (_variable) Single underscore → “internal use” warning. class Student: def __init__(self): self._marks = 85 s = Student() pr...