Data classes
Let's now discuss a new feature that was added in Python 3.7—data classes. First of all, data classes are just syntactic sugar (simpler syntax). The end result is just an ordinary instance of a class, and it can be achieved with normal classes, just in a few more lines. As the name implies, data classes are a simple way to write data-focused classes.
What do we mean by data-focused? Basically, data classes have the __repr__ and __init__ methods defined out of the box. By specifying additional parameters, such as eq, order, and frozen, we can make a data class generate additional boilerplate methods—such as equality (eq), smaller/greater (order), and add immutability (frozen). One caveat is that the default initiation function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access