Encapsulation in Python — a practical guide to Python encapsulation with clear examples you can reuse in real projects.
Python Tutorial Series (49/95). Prefer one article? Read the complete Python tutorial.
Short description
Python uses conventions (`_protected`, `__private`) and `@property` instead of strict access modifiers.
Property example
class Account:
def __init__(self, balance):
self._balance = balance
@property
def balance(self):
return self._balance
print(Account(500).balance)