forked from fluentpython/example-code-2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcards.doctest
22 lines (19 loc) · 829 Bytes
/
cards.doctest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
>>> from cards import Card
>>> helen = Card('Q', 'hearts')
>>> helen
Card(rank='Q', suit='hearts')
>>> cards = [Card(r, s) for s in Card.suits for r in Card.ranks]
>>> cards[:3]
[Card(rank='2', suit='spades'), Card(rank='3', suit='spades'), Card(rank='4', suit='spades')]
>>> sorted(cards)[:3]
[Card(rank='2', suit='clubs'), Card(rank='2', suit='diamonds'), Card(rank='2', suit='hearts')]
>>> from cards_enum import Card, Suit, Rank
>>> helen = Card('Q', 'hearts')
>>> helen
Card(rank='Q', suit='hearts')
>>> cards = [Card(r, s) for s in Suit for r in Rank]
>>> cards[:3]
[Card(rank='2', suit='spades'), Card(rank='3', suit='spades'), Card(rank='4', suit='spades')]
>>> sorted(cards)[:3]
[Card(rank='2', suit='clubs'), Card(rank='2', suit='diamonds'), Card(rank='2', suit='hearts')]
>>> for card in cards[12::13]: print(card)