diff options
author | Hui Lan <lanhui@zjnu.edu.cn> | 2019-05-13 14:24:52 +0800 |
---|---|---|
committer | Hui Lan <lanhui@zjnu.edu.cn> | 2019-05-13 14:24:52 +0800 |
commit | 6636897dadc683704243ef5d51c8f1c9bb7c2c6f (patch) | |
tree | 4d4379f882d5212f2dc1fdbe1e6159c981797bce /LectureNotesOnPython.rst | |
parent | a4d1530c4505ac07cf8553f256a929e782670010 (diff) |
LectureNotesOnPython.rst: add a __len__ method for Deck.
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r-- | LectureNotesOnPython.rst | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst index 647835a..c8d4c06 100644 --- a/LectureNotesOnPython.rst +++ b/LectureNotesOnPython.rst @@ -1979,7 +1979,10 @@ IS-A 。 一手牌是一副牌。 for card in self.cards: res.append(str(card)) return '\n'.join(res) - + + def __len__(self): + return len(self.cards) + def add_card(self, card): """Adds a card to the deck. @@ -2036,9 +2039,9 @@ IS-A 。 一手牌是一副牌。 deck.move_cards(hand, 5) hand.sort() print(hand) + hand.move_cards(deck, 5) - 用于数据库操作。以 SQLite 为例子。 |