Data Class: Data Class is a type of class that is used to store data without any functionality. These data classes are just regular classes having the main purpose to store state and data without knowing the constraints and logic behind it. Whenever you create a class that mostly contains attributes and certain properties to deal with the data and its representation.
GfgArticle(topic=’DataClasses’, contributor=’nightfury1’, language=’Python’, upvotes=1)
NamedTuple: The NamedTuple is a class that contains the data like a dictionary format stored under the ‘collections‘ module. It stored the data in a key-value format where each key having mapped to more values. So, we access those data using a specific key or can use the indexes.
The Article Topic : Difference between DataClass vs NamedTuple vs Object in Python
The Article Contributor Name : night_fury1
The Article Contributor Post : Technical Content Writer Intern
Object: An object is simply a collection of data (variables) and methods (functions) that act on those data. In other words, we say that Object is an instance of the class.
Article: Difference between DataClass vs NamedTuple vs Object in Python
Table of difference between DataClass, NamedTuple and Object
|Creation||DataClass is slower than others while creating data objects (2.94 µs).||NamedTuple is the faster one while creating data objects (2.01 µs).||An object is slower than DataClass but faster than NamedTuple while creating data objects (2.34 µs).|
|Read Property||Equal to Object & faster than NamedTuple while reading the data objects (24.7 ns).||NamedTuple is slower than others in reading data objects (26.9 ns).||Equal to DataClass & Faster than NamedTuple (24.7 ns).|
|Nested Property||Faster than others while nesting data objects & their properties (48.1 ns).||Slower than others in nesting data objects (75.8 ns).||Faster than NamedTuple but slower than DataClass (52.1 ns).|
|Execute Function||Faster than NamedTuple but slower than objects (829 ns).||Slower than others in Function Execution (946 ns).||Fastest in Function execution on data objects (821 ns).|
|Size||56 bytes||80 bytes||56 bytes|
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to use NamedTuple and Dataclass in Python?
- Data Classes in Python | Set 3 (dataclass fields)
- Creating nested dataclass objects in Python
- Namedtuple in Python
- typing.NamedTuple – Improved Namedtuples
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Python - Read blob object in python using wand library
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- Data type Object (dtype) in NumPy Python
- Python __iter__() and __next__() | Converting an object into an iterator
- Python Object Comparison : "is" vs "=="
- Python | object() method
- Python | Convert dictionary object into string
- Python | Matplotlib Sub plotting using object oriented API
- Python | Ways to convert string to json object
- Python | dtype object length of Numpy array of strings
- Python | Check if a given object is list or not
- Python | Matplotlib Graph plotting using object oriented API
- Python | os.environ object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.