길/Python

Class Properties

7he8oy 2021. 2. 13. 08:54
sclass Pizza:
    def __init__(self, toppings):
        self.toppings = toppings

    @property
    def pineapple_allowed(self):
        return False

pizza = Pizza(["cheese", "tomato"])
print(pizza.pineapple_allowed) # < - False
pizza.pineapple_allowed = True # <- error

' > Python' 카테고리의 다른 글

str.isdigit()  (0) 2021.02.13
Class Methods / Static Methods / Properties  (0) 2021.02.13
Data Hiding  (0) 2021.02.12
Object Lifecycle / reference count  (0) 2021.02.12
클래스 / 객체 / 인스턴스 구분  (0) 2021.02.12