About 1,170,000 results
Open links in new tab
  1. types - What are "named tuples" in Python? - Stack Overflow

    Jun 4, 2010 · Named tuples are basically easy-to-create, lightweight object types. Named tuple instances can be referenced using object-like variable dereferencing or the standard tuple …

  2. python - Type hints in namedtuple - Stack Overflow

    Dec 14, 2015 · ^^ While the keyword-argument syntax mentioned by @MarkedasDuplicate still works (tested on Python 3.10.9 (tags/v3.10.9:1dd9be6)), it was removed from the docstrings in …

  3. namedtuple vs NamedTuple in Python - Stack Overflow

    The type generated by subclassing typing.NamedTuple is equivalent to a collections.namedtuple, but with __annotations__, _field_types and _field_defaults attributes added. The generated …

  4. Named tuple and default values for optional keyword arguments

    Jul 6, 2012 · In all versions of Python, if you set fewer default values than exist in the namedtuple, the defaults are applied to the rightmost parameters. This allows you to keep some arguments …

  5. Data Classes vs typing.NamedTuple primary use cases

    Aug 3, 2018 · PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.namedtuple and typing.NamedTuple. And now I'm wondering how …

  6. Python: Extending a predefined named tuple - Stack Overflow

    Feb 13, 2015 · 44 You can subclass a namedtuple -produced class, but you need to study the generated class more closely. You'll need to add another __slots__ attribute with the extra …

  7. python - Adding docstrings to namedtuples? - Stack Overflow

    Oct 22, 2009 · Here is a good example of a NamedTuple that is documented with a Docstring. (Python 3.6+) Below the example, you will find my reasoning on why this is a good example.

  8. python - Convert a namedtuple into a dictionary - Stack Overflow

    class Town(collections.namedtuple('Town', [ 'name', 'population', 'coordinates', 'population', 'capital', 'state_bird'])): # ... I'd like to convert Town instances into dictionaries. I don't want it to …

  9. python - When and why should I use a namedtuple instead of a …

    Mar 26, 2012 · The standard library namedtuple class looks to me like a way to make tuples more like dictionaries. How do namedtuples compare to dicts? When should we use them? Do they …

  10. namedtuple - Looping over elements of named tuple in python

    Nov 29, 2015 · Looping over elements of named tuple in python Asked 10 years ago Modified 1 year, 1 month ago Viewed 47k times