Using Data Classes in Python (Overview)
One new and exciting feature that came out in Python 3.7 was the data class. A data class is a class typically containing mainly data, although there aren’t really any restrictions.
With data classes, you don’t have to write boilerplate code to get proper initialization, representation, and comparisons for your objects.
In this course, you’ll learn how to:
- Define your own data classes
- Add default values to the fields in your data class
- Customize the ordering of data class objects
- Work with immutable data classes
00:04 Data classes were introduced with Python 3.7 and they’re a class which typically contain mainly data, although there aren’t really any restrictions. They provide a convenient way to define classes which exist primarily to store data and allow value retrieval via attribute lookup.
00:23 In this video course, you’ll learn exactly which conveniences data classes provide. In addition to nice representations and comparisons, you’ll see how to add default values to data class fields, how data classes allow for ordering of objects, how to represent immutable data, and how data classes handle inheritance. So, with no further ado, let’s take a look at a comparison between using a data class and a standard class for storing data.
Become a Member to join the conversation.