I know how to do this in Java, but it seems to have a little different syntax in Python. I have two separate classes, Fruit, and FruitBasket. I'm going to be adding a lot more functions to each classes, but they all involve passing objects around as parameters, which I'm not exactly sure how to do. This is the very basic foundation of the code.
Problem: I need to figure out how to pass a Fruit object to addFruit(fruit object) in FruitBasket. Would I pass something like fruit.Fruit? or fruit = Fruit()?
Problem: I need to figure out how to pass a Fruit object to addFruit(fruit object) in FruitBasket. Would I pass something like fruit.Fruit? or fruit = Fruit()?
class Fruit(object): def __init__(self, typeOfFruit, number, color): self.theType = typeOfFruit self.theNumber = number self.theColor = color
class FruitBasket(object): def __init__(self): #the basket is empty upon initialization self.theBasket = [] def addFruit(self, FRUIT OBJECT GOES HERE): #SET THE FRUIT OBJECT EQUAL TO SOMETHING? self.theBasket.append(FRUIT OBJECT GOES HERE)