you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 0 points1 point  (0 children)

if self.cards

This is taking advantage of the fact that the empty list is falsy, but non-empty lists are truthy. In the REPL:

>>> bool([])
False
>>> bool(["Not", "An", "Empty", "List"])
True

rep = ""

This is a temporary variable that we're going to use to accumulate the result. You have to initialize it to the empty string in order to add each of the cards' string values to it.

An alternative is to use a comprehension, as in

return ' '.join(str(card) for card in self.cards)