Private Methods in Python

Python Methods and Functions

Prerequisites —

Encapsulation is one of fundamental concepts in object-oriented programming (OOP). He describes the idea of ​​packaging data and methods that work with data in a single block. This places restrictions on direct access to variables and methods and can prevent accidental data changes. The class is an example of encapsulation as it encapsulates all data that is member functions, variables, etc.

Now there may be some scenarios where we need to impose constraints on some of the class's methods so that they cannot be accessible neither outside the class nor by subclasses. Private methods come into play to accomplish this.





Get Solution for free from DataCamp guru