In [1]:
from collections import namedtuple

In [2]:
City = namedtuple('City', 'name country population coordinates')
tokyo = City('Tokyo', 'JP', 36.933, (35.689722, 139.691667))

In [3]:
tokyo


Out[3]:
City(name='Tokyo', country='JP', population=36.933, coordinates=(35.689722, 139.691667))

In [4]:
tokyo.population


Out[4]:
36.933

In [5]:
tokyo.coordinates


Out[5]:
(35.689722, 139.691667)

In [6]:
tokyo[1]


Out[6]:
'JP'

In [7]:
City._fields


Out[7]:
('name', 'country', 'population', 'coordinates')

In [8]:
LatLong = namedtuple('LatLong', 'lat long')

In [9]:
delhi_data = ('Delhi NCR', 'IN', 21.935, LatLong(28.613889, 77.208889))

In [10]:
delhi = City._make(delhi_data)

In [11]:
delhi


Out[11]:
City(name='Delhi NCR', country='IN', population=21.935, coordinates=LatLong(lat=28.613889, long=77.208889))

In [12]:
delhi._asdict


Out[12]:
<bound method City._asdict of City(name='Delhi NCR', country='IN', population=21.935, coordinates=LatLong(lat=28.613889, long=77.208889))>

In [13]:
delhi._asdict()


Out[13]:
OrderedDict([('name', 'Delhi NCR'),
             ('country', 'IN'),
             ('population', 21.935),
             ('coordinates', LatLong(lat=28.613889, long=77.208889))])

In [14]:
for key, value in delhi._asdict().items():
    print(key + ':', value)


name: Delhi NCR
country: IN
population: 21.935
coordinates: LatLong(lat=28.613889, long=77.208889)