Код: Выделить всё
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
Что такое классы данных и когда их лучше всего использовать?>
Подробнее здесь: https://stackoverflow.com/questions/479 ... on-classes
Мобильная версия