Loading…
Composition means an object contains other objects:
class Engine:
def __init__(self, horsepower):
self.horsepower = horsepowerclass Car:
def __init__(self, brand, engine):
self.brand = brand
self.engine = engine # Car HAS an Engine
engine = Engine(200)
car = Car("Toyota", engine)
print(car.engine.horsepower) # 200
Create:
Expense class with description and amountExpenseReport class that takes a name and a list of expensesThe ExpenseReport should store the expenses list.
Downloading Python… (one-time, ~10 MB)
This runs entirely in your browser and is cached for next time.