Created
July 22, 2016 15:37
-
-
Save nuhil/ad5e21c37ee4ac3aee5f6517d0d2faff to your computer and use it in GitHub Desktop.
Python Property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == "123456": | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment