더북(TheBook)

나머지 메서드는 Deck에서 상속받은 것으로 pop_cardadd_card를 사용해 카드를 다룰 수 있다.

>>> deck = Deck()

>>> card = deck.pop_card()

>>> hand.add_card(card)

>>> print(hand)

King of Spades

다음 단계는 당연하게도 move_cards 메서드에 이 코드를 캡슐화하는 것이다.

#class Deck: 정의

 

def move_cards(self, hand, num):

for i in range(num):

hand.add_card(self.pop_card())

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.