Encapsulation
say it: “en-KAP-suh-LAY-shun” /ɛnˌkæpsəˈleɪʃən/
Keeping an object's data behind its methods so it's changed the safe way.
What is encapsulation?
Encapsulation means keeping an object's data behind its own methods, so the rest of the program changes it the safe way instead of poking at it directly.
class BankAccount:
def __init__(self):
self._balance = 0
def deposit(self, amount):
if amount > 0: # the method guards the data
self._balance += amount
Level: Journeyman · More Python terms at this level
Updated