Encapsulation is one of the fundamental concepts in object-oriented programming (OOP), including abstraction, inheritance, and polymorphism. This lesson will cover what encapsulation is and how to implement it in Python.
After reading this article, you will learn:
- Encapsulation in Python
- Need for Encapsulation
- Data Hiding using public, protected, and private members
- Data Hiding vs. Encapsulation
- Getter and Setter Methods
- Benefits of Encapsulation
Table of contents
What is Encapsulation in Python?
Encapsulation in Python describes the concept of bundling data and methods within a single unit. So, for example, when you create a class, it means you are implementing encapsulation. A class is an example of encapsulation as it binds all the data members (instance variables) and methods into a single unit.