From the course: Python Object-Oriented Programming
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Defining a data class - Python Tutorial
From the course: Python Object-Oriented Programming
Defining a data class
- [Voiceover] As we've been working through the course you may have noticed a pattern with each of our examples so far, and that is that one of the main use cases for creating classes in Python is to contain and represent data. Our code creates classes, and let's go ahead and open up the data class underscore start example. So our code creates classes like this book class here in our start file and then uses the init function to store values on the instance of the class. And you might be wondering, "Well if this is such a common pattern then why doesn't Python just automate this? Why do I have to explicitly store each argument on the object by setting attributes on the self parameter?" Well, starting back in 3.7 which was released a little while ago, you actually don't need to do this anymore. In 3.7 Python introduced a new feature called the Data Class which helps to automate the creation and managing of classes that…