In the example provided by Martijn Pieters in What are data classes and how are they different from common classes?, he defines some class members in the class header, as well as in __init__()
:
class InventoryItem:
'''Class for keeping track of an item in inventory.'''
name: str
unit_price: float
quantity_on_hand: int = 0
def __init__(
self,
name: str,
unit_price: float,
quantity_on_hand: int = 0
) -> None:
self.name = name
self.unit_price = unit_price
self.quantity_on_hand = quantity_on_hand
...
What is the reason to do that, is it not enough to define them in __init__()
?