Skip to content

Instantly share code, notes, and snippets.

@ychennay
Last active Mar 21, 2020
Embed
What would you like to do?
class StudentWithStaticProp:
def __init__(self):
self._name = "Default Name"
def _name(self):
return "A new name, never changes"
name = property(_name)
if __name__ == "__main__":
student = StudentWithStaticProp()
print(student.name) # An immutable attribute
del student.name # AttributeError: can't delete attribute
student.name = "Yu" # AttributeError: can't set attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment