3 ms·
I feel like none of the sibling answers actually answer your question which is "absolutely nothing." The function namedtuple is code generator that constructs a
by Spivak 5y ago
I feel like none of the sibling answers actually answer your question which is "absolutely nothing." The function namedtuple is code generator that constructs a class definition and then eval()'s it.
The reason you reach for it is because it's tedious to write the same methods over and over to get things like a nice repr, methods covert between dicts, or pickling support.
The source from Python 3.6 is much more readable than 3.9 so I recommend reading that if you want to see how it works.
https://github.com/python/cpython/blob/3.6/Lib/collections/__init__.py https://github.com/python/cpython/blob/3.6/Lib/collections/_...