from dataclasses import dataclass, field @dataclass class Product: name: str price: float stock: int = field(default=10) # 預設庫存為 10 product = Product(name="Laptop", price=999.99) print(product) # Product(name='Laptop', price=999.99, stock=10)