# convention: _<name> for protected and __<name> for private
class MyClass:
def __init__(self):
# Protected
# No access outside of the class or subclasses
self._this_is_protected = True
# Private
# No access outside of the class
self.__this_is_private = True
# Note:
# Private and protected members can be accessed outside of the class using python name mangling.
class Computer:
def __init__(self):
self.__maxprice = 900
def sell(self):
print("Selling Price: {}".format(self.__maxprice))
def setMaxPrice(self, price):
self.__maxprice = price
c = Computer()
c.sell()
# change the price
c.__maxprice = 1000
c.sell()
# using setter function
c.setMaxPrice(1000)
c.sell()