Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created June 13, 2020 08:53
Show Gist options
  • Save ZhouYang1993/604bae0d4fc83c36af5afc4c6e7aec28 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/604bae0d4fc83c36af5afc4c6e7aec28 to your computer and use it in GitHub Desktop.
Understand the Property Decorator in Python
class Student:
def __init__(self):
self._score = 0
def set_score(self, s):
if 0 <= s <= 100:
self._score = s
else:
raise ValueError('The score must be between 0 ~ 100!')
Yang = Student()
Yang.set_score(100)
print(Yang._score)
# 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment