#import the namedtuple factory method from collections import namedtuple #create a namedtuple to represent a Point Point = namedtuple('Point', ['x', 'y']) #Create objects from the namedtuple 'Point' p = Point(3, 4) #Access the elements using the numeric indices print(p[0], p[1]) #Access the elements using their names print(p.x, p.y)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter