Private Attributes in Python

Python allows us to define private attributes in our class (private instance variables). Outside the scope of the class it won’t be possible to access them. In order to create private attributes we should prefix their names with two underscores (‘__’). class Rectangle: def __init__(self,w=10,h=10): self.__width = w self.__height = h def area(self): return self.__width*self.__height […]

Skip to content Update cookies preferences