Created
March 21, 2020 04:14
-
-
Save ychennay/4f620ca208c498c243d03deafa96222e to your computer and use it in GitHub Desktop.
properties
This file contains 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
# both classes below implement Python properties using data descriptors | |
class StudentWithInlineProps: | |
def __init__(self, name="Default Name"): | |
self._name = name | |
# getting the values | |
def get_name(self): | |
print('Getting value') | |
return self._name | |
# setting the values | |
def set_name(self, value): | |
self._name = value | |
name = property(get_name, set_name) | |
class StudentWithDecoratorProps: | |
def __init__(self, name="Default Name"): | |
self._name = name | |
@property | |
def name(self): | |
return self._name | |
@name.setter | |
def name(self, name): | |
self._name = name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment