python纸牌类TypeError: object of type 'FrenchDeck' has no len()

import collections
Card=collections.namedtuple('Card',['rank','suit'])

class FrenchDeck:
    ranks = [str(n) for n in range(2,11)] + list('JKQA')
    suits = 'spades diamonds clubs hearts'.split( )

def __init__(self):
        self._cards = [Card(rank,suit) for suit in self.suits
                                  for rank in self.ranks]
def __len__(self):
        return len(self._cards)

def __getitem__(self,position):
        return self._cards[position]

为什么用len()显示TypeError: object of type 'FrenchDeck' has no len()

查看全部
weixin_44220949
lllrc
2019/06/24 16:46
  • python
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复