10/18 - Explaining the line that defines price


Someone else had asked this question (link here: It’s Not All Animals and Fruits) but it didn’t get answered in time, so I’m asking it here because I have the same question.

How does Python know to associate line 11 with the ‘price’ variable when it’s only referencing the empty member list and the other attribute?

Thank you.


line 11 is adding key value pair to the dictionary (items_in_cart is a dictionary), the price comes from calling add_item method which you do on line 25 and 26


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.