Created
June 13, 2020 08:53
-
-
Save ZhouYang1993/604bae0d4fc83c36af5afc4c6e7aec28 to your computer and use it in GitHub Desktop.
Understand the Property Decorator in Python
This file contains hidden or 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 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