- 1

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)

11th Apr 2019, 12:15 AM
Joe Lishuai Lin
Joe Lishuai Lin - avatar
1 Odpowiedź
+ 2
Q1= after if a condition comes that if the condition was false the statements of the if wont executed and if it was true the statements will be executed. the following text will show how a var can be false: 1-boolean=when we assign it to false 2-string,list,int= when it has nothing on it (its null like this: var="") Q2= idon't get your mean fully, if you explain more maybe i can answer.
11th Apr 2019, 8:20 AM
alireza
alireza - avatar