Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
properties
# 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