AI engineering glossary · Python advanced
What is encapsulation?
Encapsulation: Bundling data with the methods that use it and limiting direct outside access to the internals. It protects an object's state from accidental misuse and lets the internal design change without breaking users of the class.
Encapsulation: an example
A BankAccount keeps _balance internal and exposes deposit() and withdraw(), which check that the amount is valid.
Related terms
More Python advanced terms
- Fixture
- functools
- functools.lru_cache
- functools.partial
- functools.wraps
- Future
- Generator
- Generator expression
Where you learn it
Encapsulation is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.