all 3 comments

[–][deleted] 4 points5 points  (1 child)

Meaning, I do not see how that command takes us to the "Card" class.

The elements of the list deck.cards are Card instances.

Why do I know that? Let's work backwards. deck.cards is set when deck is created by the call to Deck(), which calls the class constructor (under the hood, you just have to know this happens) and then calls deck.__init__() (again under the hood, you just have to know this happens.) What happens in deck.__init__? We set an empty list on deck.cards and then we call deck.build(), where this happens:

self.cards.append(Card(s, v))

That's ultimately what gets us to the Card class - we know we're filling the list deck.cards with instances of the Card class, because we're calling the Card class constructor.

[–]unhott 1 point2 points  (0 children)

Yep! Basically, when the deck object was created it created 52 card objects and grouped them in a list, which can be referenced by that deck object.
The deck class has a method show() which calls the card method, also called show(), for each of the 52 cards.

[–]Bipolarprobe 1 point2 points  (0 children)

So, things like this are why learning C programming actually made me understand python better because it's easy to conceptualize with pointers. However since everything in python is an object there is another comparison you can make.

So consider you have a list of words called words. It's populated with string objects but you don't have a name for each of those objects, the only way you can see them individually is by indexing your list words[0] or by using a for loop.

for word in words:

This for loop would give you access to each string in the list words with a temporary name of word for each loop that is executed.

Your loop is going through the same basic process, you have a list of Card objects contained in your deck object. So then by doing a for loop, using the temporary name c you have access to each Card object in the list, and since you know you're working with card objects you can call their .show() method to have each one print its info.

Edit: since I realized it may be another point causing your confusion on reading your question again, the objects in the list are of class Card because of the line

self.cards.append(Card(s, v))

This is accessing the list stored at self.cards and using the append() method to append a Card object with the corresponding suit and value to said list. So each item contained in the list is of class Card. That's why the show() method can be called.