Dup Goto 📝

DataClasses

PT2/aw/lang/python 07-31 13:46:41
To Pop
15 lines, 35 words, 356 chars Monday 2023-07-31 13:46:41

docs

from dataclasses import dataclass

@dataclass
class InventoryItem:
    """Class for keeping track of an item in inventory."""
    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand