Created
August 14, 2018 03:21
-
-
Save luojiyin1987/077da440b609ba8f8a68c166503586bb to your computer and use it in GitHub Desktop.
Mylist
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
| 其次,如果想要在 Python shell (Python的互動介面)中能夠只利用變數名稱就展示用來表示 Mylist 的字串,光是 __str__ 還不夠,這必須要覆寫 __repr__: | |
| class Mylist: | |
| def __init__(self): | |
| self._mylist=list() | |
| def __len__(self): | |
| return len(self._mylist) | |
| def add(self,value): | |
| return self._mylist.append(value) | |
| def __str__(self): | |
| return str(self._mylist) | |
| def __repr__(self): | |
| return str(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment