python access modifiers

Solutions on MaxInterview for python access modifiers by the best coders in the world

showing results for - "python access modifiers"
Iliana
24 Sep 2016
1# In python access modifying can be done by prefixing the underscore character '_' to the variable name.
2
3# Prefixing no underscores makes the variable public.
4# Prefixing 1 underscore makes the variable protected.
5# Prefixing 2 underscores makes the variable private.
6
7# In the following example, name is public, __make is private, _model is protected.
8class Car:
9    def __init__(self):
10        print("Engine started")
11        self.__make = "toyota"
12        self._model = 1999
13        self.name = "corolla"
similar questions
queries leading to this page
python access modifiers