Skip to content

Instantly share code, notes, and snippets.

@ychennay
Last active March 21, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/fb3a4efddbd64b7478e51c04e1929e0b to your computer and use it in GitHub Desktop.
Save ychennay/fb3a4efddbd64b7478e51c04e1929e0b to your computer and use it in GitHub Desktop.
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