dataclass
A class decorated with @dataclass from the dataclasses module, which writes __init__, __repr__ and __eq__ for you from a list of annotated fields.
In more detail
It suits plain data records. frozen=True makes instances immutable and hashable.
Example
from dataclasses import dataclass
@dataclass
class Point:
x: float
y: floatRelated terms
- decorator — A line starting with @ placed above a function or class that wraps it to add behaviour or information.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- type hint — A note in a function heading or variable declaration saying what type a value should be, such as def total(prices: list[float]) -> float:.
- __repr__ — __repr__ returns an unambiguous text form of an object for programmers; __str__ returns a friendly one for readers, used by print.
Taught in
- Dunder Methods, And Making Objects Pythonic — Hands-on Python: Complete Video Course & Book
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book