Here’s a link to the exercise I am on: https://www.codecademy.com/courses/learn-python/lessons/introduction-to-classes/exercises/its-not-all-animals-and-fruits
I’m wondering why, in the ‘add_item’ function, they use self.items_in_cart(product) = price. I mean, why is self used first? How come it isn’t just items_in_cart(product) = price.
Here’s the code:
def add_item(self, product, price): """Add product to the cart.""" if not product in self.items_in_cart: self.items_in_cart[product] = price print product + " added." else: print product + " is already in the cart."