Python, Encapsulation / Data Hiding.
#Sharing a code from Sololearn's Module: class Pizza: def __init__(self, toppings): self.toppings = toppings self._pineapple_allowed = False @property def pineapple_allowed(self): return self._pineapple_allowed @pineapple_allowed.setter def pineapple_allowed(self, value): if value: password = input("Enter the password: ") if password == "Sw0rdf1sh!": self._pineapple_allowed = value else: raise ValueError("Alert! Intruder!") pizza = Pizza(["cheese", "tomato"]) print(pizza.pineapple_allowed) pizza.pineapple_allowed = True print(pizza.pineapple_allowed) #I am unable to understand the role of setter method here! My interpretation: The last 4th line of code creates an instance. The last third line refers to the pineapple_allowed(self) method which returns the False statement because of __init__. I am unable to understand the rest please help. Sorry if the question is lengthy! Thanks in Advance.