Last active
March 21, 2020 17:44
-
-
Save ychennay/fb3a4efddbd64b7478e51c04e1929e0b to your computer and use it in GitHub Desktop.
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
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