Skip to content

Instantly share code, notes, and snippets.

@nuhil
Created July 22, 2016 15:37
Show Gist options
  • Save nuhil/ad5e21c37ee4ac3aee5f6517d0d2faff to your computer and use it in GitHub Desktop.
Save nuhil/ad5e21c37ee4ac3aee5f6517d0d2faff to your computer and use it in GitHub Desktop.
Python Property
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