From 6636897dadc683704243ef5d51c8f1c9bb7c2c6f Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 13 May 2019 14:24:52 +0800 Subject: LectureNotesOnPython.rst: add a __len__ method for Deck. --- LectureNotesOnPython.rst | 7 +++++-- 1 file 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 为例子。 -- cgit v1.2.1