Python exercise · about 5 minutes · free
dataclasses: Records Without Boilerplate
Most classes in data code are just records. @dataclass writes __init__, __repr__ and __eq__ for you.
A decorator is the @name line written just above a class or function: it hands that class to another piece of code, which adds features to it. Decorate a class with @dataclass and list fields with type hints. For mutable defaults like lists, use field(default_factory=list) so objects don't share one list.
Prices, versions and service names last checked 2026-11-18. They change, so confirm on the official pages before you rely on them.
Your quest: Define dataclass
Item with name: str, price: int and tags: list (default empty list), then create sword = Item("Sword", 150, ["melee"]).Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hint
@dataclass class Item: name: str price: int tags: list = field(default_factory=list)Output appears here.