Encapsulation in Python
Encapsulation keeps data with the methods that are allowed to change it. On a bank account, Main should call deposit(100), not poke a.balance = -9. You hide the field with _balance or __balance and expose deposit / get_balance. The object protects its own rules — amount must be > 0.
Dry-run: Account starts at 0. deposit(100) → 100. deposit(-50) ignored. get_balance() prints 100. __balance is not for Main to touch. That is encapsulation for a fresher — not a long OOP essay.
Encapsulation in Python — output — 100. deposit(-50) ignored. __balance is not for Main to poke.
Account
__balance
│ only via
▼
deposit() / get_balance()__balance + deposit that rejects negatives.