M
M
Mark2021-12-01 00:46:33
Python
Mark, 2021-12-01 00:46:33

How to assign an object to a method argument in another class?

I started learning OOP and ran into a problem. I am writing a shopping cart program.

class Product:

    def __init__(self, name, price):
        self.name = name
        self.price = price

    def get_total(self, units):
        result = self.price * units
        return result


class Cart:
    def __init__(self):
        self.list_product = list()
        self.units = list()

    def add(self, product, units):
        ...

How to throw the data of my "Product" object into my "product" from the "def add(self, product, units):" method

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question