My python list comprehension fails due to a syntax error
<p>Python noob using version 3.2.3...</p>

<pre><code>class Card:
    def __init__(self, suitID, rank):
            self.suits = ("Spades", "Hearts", "Diamonds","Clubs")
            self.rank = rank
            self.suit = self.suits[suitID]

    def __str__(self):
            return (str("%s of %s" % (self.rank, self.suit)))


class Deck:
    def __init__(self):
            self.cards = [Card(i//13, i%13) for i in range(52)]
</code></pre>

<p>The above is how I have things set up, seems fine to me. The confusion is in the following (please ignore the <strong>return ("")</strong> statement as this is only for testing)</p>

<p><strong>Case 1:</strong></p>

<pre><code>def __str__(self):
    print ( self.cards [i for i in range (52) ] )
    return("")
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>File "cardgame.py", line 21
print (self.cards[i for i in range(52)])
                      ^
SyntaxError: invalid syntax
</code></pre>

<p>Why the error? I thought that was how LC's were used...</p>

<hr>

<p><strong>Case 2:</strong></p>

<pre><code>def __str__(self):
    print (myCards for myCards in self.cards)
return ("")
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>&lt;generator object &lt;genexpr&gt; at 0x2256fa0&gt;
</code></pre>

<p>Again, what does that mean, and why does it not output the data?</p>

<hr>

<p><strong>Case 3:</strong></p>

<pre><code>def __str__(self):
    for myCard in self.cards:
          print (myCard)
    return ("")
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>0 of Spades
1 of Spades
2 of Spades
3 of Spades
4 of Spades
...
..
.
</code></pre>

<p>Now this outputs exactly what I want, but that confuses me ever more. I was under the impression that all three cases are equivalent and they are clearly not. What are the differences?</p>

<p>Thanks in advance.</p>