Courses/Modern Python

๐Ÿš€ Modern Python

Dataclasses

Boilerplate-free classes for holding data.

@dataclass auto-generates __init__, __repr__, and __eq__ from your fields.

from dataclasses import dataclass

@dataclass
class Point:
    x: float
    y: float

print(Point(1.0, 2.0))
main.py
Output
Press Run to execute.
Expected output
Book(title='Fluent Python', pages=800)

Sign in to track your progress across lessons.