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