Skip to content

Encapsulation and Abstraction in Python

Python – Advanced OOP

As we read earlier about Python Polymorphism Now we will study about Encapsulation and Abstraction in python. In the advanced concept of OOP, Encapsulation is the third principle of Object – Oriented Programming and Abstraction is the last principle of Object – Oriented Programming. so let’s start.

What is Encapsulation in Python ?

Encapsulation is the fundamental concepts in object-oriented programming. It means that the process of wrapping up variables and objects into a single entity is known as encapsulation. The best example of encapsulation is creating a class , the class holds all the data and methods together it also provides your code – security, flexibility and its easy maintainability through encapsulation. It is also useful in hiding the data(instance variables) of a class from an illegal direct access.

What is Abstraction in Python ?

Abstraction is the process of hiding the real implementation of an application from the user and focusing only on the usage of it. For example, examine you have bought a new toaster, you just need to turn on the toaster and put the bread in it and after that, your toast is ready. you don’t really need to know the internal working of the toaster.

Encapsulation and Abstraction in python are the two important Object Oriented Programming (OOPS) concepts. Encapsulation and Abstraction both are interrelated terms.