May 2018
Intermediate to advanced
380 pages
9h 37m
English
As seen in the preceding examples, named tuples have special methods and attributes available to them, as well as the methods available to normal tuples. The namedtuple methods and attributes are denoted with an underscore prefix to ensure that they don't conflict with field names, as shown here:
>>> t = [12, 34] >>> Point._make(t) Point(x=12, y=34)
>>> p = Point(x=12, y=34) >>> p._asdict() OrderedDict([('x', 11), ('y', 22)])>
Read now
Unlock full access