IndexError: list index out of range in Python 3
<p>I am newbie to Python. I got the index error when I run the code. I have seen the relevant questions in Stackoverflow, but I still can't see what the bug is. I am very appreciated for any response. Thank you. Here is the code:</p>

<pre><code> class Card:
   def __init__(self, suit = 0, rank = 2):
       self.suit = suit
       self.rank = rank

   suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
   rank_names =[None,'Ace','2','3','4','5','6','7','9','10','Jack','Queen', 'King']

   def __str__ (self):
       return '%s of %s' % (Card.rank_names[self.rank], Card.suit_names[self.suit])

   def __lt__(self,other):
       t1 = self.suit, self.rank
       t2 = other.suit, other.rank
       return t1 &lt; t2


class Deck:
   def __init__(self):
       self.cards = []
       for suit in range(4):
           for rank in range(1, 14):
               card = Card(suit, rank)
               self.cards.append(card)

   def __str__(self):
       res = [ ]
       for card in self.cards:
           res.append(str(card))
       return '\n'.join(res)


deck1 = Deck()
print(deck1)
</code></pre>

<p>Then I got the following error:</p>

<pre><code>   Traceback (most recent call last):
  File "/Users/Enze/Python/untitled/Inheritance.py", line 35, in &lt;module&gt;
    print(deck1)
  File "/Users/Enze/Python/untitled/Inheritance.py", line 30, in __str__
    res.append(str(card))
  File "/Users/Enze/Python/untitled/Inheritance.py", line 11, in __str__
    return '%s of %s' % (Card.rank_names[self.rank], Card.suit_names[self.suit])
IndexError: list index out of range
</code></pre>

<p>use are missing '8' in rank_names</p>

<pre><code>class Card:
   def __init__(self, suit = 0, rank = 2):
       self.suit = suit
       self.rank = rank

   suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
   rank_names =[None,'Ace','2','3','4','5','6','7','8','9','10','Jack','Queen', 'King']

   def __str__ (self):
       return '%s of %s' % (Card.rank_names[self.rank], Card.suit_names[self.suit])

   def __lt__(self,other):
       t1 = self.suit, self.rank
       t2 = other.suit, other.rank
       return t1 &lt; t2


class Deck:
   def __init__(self):
       self.cards = []
       for suit in range(4):
           for rank in range(1, 14):
               card = Card(suit, rank)
               self.cards.append(card)

   def __str__(self):
       res = [ ]
       for card in self.cards:
           res.append(str(card))
       return '\n'.join(res)


deck1 = Deck()
print(deck1)
</code></pre>

python