namedtuples in collections module

PHOTO EMBED

Fri Jun 21 2024 18:49:55 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

from collections import namedtuple

Point = namedtuple("Point", ['x', 'y'])

p = Point(3, 5)

print(p.x, p.y) #using attributes
print(p[0], p[1]) # using indexes
content_copyCOPY

https://www.pynerds.com/12-builtin-modules-every-python-developer-must-try/