Essential features of object oriented programming:-
- Data hiding
Data hiding is the process of hiding the details of an object and function. It is also a potent technique in programming that results in data security and less data complexity.
In python, if we want to hide the variable, then we need to write double underscore (__) before the variable name.
class democlass: __hiddenVariable = 0 def add(self, increment): self.__hiddenVariable += increment print (self.__hiddenVariable) demoobject = democlass() demoobject.add(2) demoobject.add(5) print (demoobject.__hiddenVariable)
Output- 4 12 error
This is all about data hiding in python.