Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python property

# Python @property decorator
class Foo:
    def __init__(self, my_word):
        self._word = my_word
    @property
    def word(self):
        return self._word
# word() is now a property instead of a method
print(Foo('ok').word)     # ok

class Bar:
    def __init__(self, my_word):
        self._word = my_word
    def word(self):
        return self._word
print(Bar('ok').word())   # ok   # word() is a method
 
PREVIOUS NEXT
Tagged: #Python #property
ADD COMMENT
Topic
Name
1+6 =