2 Quanstions about @property of Class
Bellow are the codes on Sololearn. 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: #Q1: Why we put "if value" here ? # What's this meaning ? password = input("Enter the password: ") if password == "Sw0rdf1sh!": self._pineapple_allowed = value else: raise ValueError("Alert! Intruder!") pizza = Pizza(["cheese", "tomato"]) print(pizza.toppings) print(pizza.pineapple_allowed) pizza.pineapple_allowed = True # Q2: here, according to the codes above, # "pizza.pineapple_allowed=False", # so why we assign False = True ? print(pizza.pineapple_allowed)