1from dataclasses import dataclass
2
3@dataclass
4class InventoryItem:
5 """Class for keeping track of an item in inventory."""
6 name: str
7 unit_price: float
8 quantity_on_hand: int = 0
9
10 def total_cost(self) -> float:
11 return self.unit_price * self.quantity_on_hand
12
1def __init__(self, name: str, unit_price: float, quantity_on_hand: int=0):
2 self.name = name
3 self.unit_price = unit_price
4 self.quantity_on_hand = quantity_on_hand
5
6 def total_cost(self) -> float:
7 return self.unit_price * self.quantity_on_hand
8
9# Is the same as:
10
11from dataclasses import dataclass
12
13@dataclass
14class InventoryItem:
15 """Class for keeping track of an item in inventory."""
16 name: str
17 unit_price: float
18 quantity_on_hand: int = 0
19
20 def total_cost(self) -> float:
21 return self.unit_price * self.quantity_on_hand
22