3 ms·
Named tuples have been around for a long time (since 2.6), whereas dataclasses are a relatively recent addition to the standard library (3.7). Their difference
by aix1 5y ago
Named tuples have been around for a long time (since 2.6), whereas dataclasses are a relatively recent addition to the standard library (3.7).
Their differences are highlighted in the dataclasses PEP: https://www.python.org/dev/peps/pep-0557/#why-not-just-use-namedtuple https://www.python.org/dev/peps/pep-0557/#why-not-just-use-n...
- nsonha 5y agolooks like the key thing is immutability
- aix1 5y agoTo clarify, both named tuples and dataclasses can be immutable (the former are always immutable and the latter can be made immutable with `frozen=True`). There is no way, however, to make a named tuple mutable.
- dreamofkoholint 5y agoKey thing for me was the ability to add type hinting