Relevance of typename in namedtuple

namedtuple, python, python-3.x, typename

Solution

`namedtuple()` is a factory function for `tuple` subclasses. Here, `'whatsmypurpose'`is the type name. When you create a named tuple, a class with this name (`whatsmypurpose`) gets created internally.

You can notice this by using the verbose argument like:

Point=namedtuple('whatsmypurpose',['x','y'], verbose=True)

Also you can try `type(p)` to verify this.

Problem

``` from collections import namedtuple Point = namedtuple('whatsmypurpose',['x','y']) p = Point(11,22) print(p) ``` Output: ``` whatsmypurpose(x=11,y=22) ``` What's the relevance/use of `'whatsmypurpose'`?

Original source

Related problems