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 | |
| @property | |
| def score(self): | |
| return self._score | |
| @score.setter | |
| def score(self, s): |
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 C(object): | |
| @property | |
| def x(self): | |
| return self._x | |
| @x.setter | |
| def x(self, value): | |
| self._x = value |
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 score(self): | |
| return self._score | |
| def set_score(self, s): | |
| if 0 <= s <= 100: | |
| self._score = s |
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 | |
| @property | |
| def score(self): | |
| return self._score | |
| @score.deleter | |
| def score(self): |
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
| A = [1, 2, 3] | |
| B = A | |
| B.append(4) | |
| print(A) | |
| # [1, 2, 3, 4] | |
| print(B) | |
| # [1, 2, 3, 4] |
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
| import copy | |
| A = [1, 2, 3] | |
| # B = A.copy() | |
| B = copy.copy(A) # The same as `B = A.copy()` | |
| B.append(4) | |
| print(A) | |
| # [1, 2, 3] |
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
| import copy | |
| A = [[1, 2], ['a', 'b']] | |
| B = copy.copy(A) # The same as `B = A.copy()` | |
| B.append(4) | |
| print(A) | |
| # [[1, 2], ['a', 'b']] | |
| print(B) | |
| # [[1, 2], ['a', 'b'], 4] |
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
| import copy | |
| A = [[1, 2], ['a', 'b']] | |
| B = copy.deepcopy(A) | |
| B.append(4) | |
| print(A) | |
| # [[1, 2], ['a', 'b']] | |
| print(B) | |
| # [[1, 2], ['a', 'b'], 4] |
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
| def f(x): | |
| return x * x | |
| r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9]) | |
| print(list(r)) | |
| # [1, 4, 9, 16, 25, 36, 49, 64, 81] |
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
| from functools import reduce | |
| city = ['L', 'o', 'n', 'd', 'o', 'n', 2, 0, 2, 0] | |
| city_to_str = reduce(lambda x, y: str(x) + str(y), city) | |
| print(city_to_str) | |
| # London2020 |