0 votes
in Education by (1.7m points)
In the python documentation, an instance of a named_tuple is created by using the below code:

Point = named_tuple('Point', ['x', 'y'])

p = Point(11, y=22)

Is it necessary to use the same variable name as the type name of named_tuple? What is the benefit of doing it?

Select the correct answer from above options

1 Answer

0 votes
by (1.7m points)
Best answer
If you use different names it will lead to unnecessary confusion.

> from collections import namedtuple

> Foo = namedtuple('Bar', ['x', 'y'])

> a = Foo(1, 2)

> print(a)

Bar(x=1, y=2)

 Do check out Data Science with Python course which helps you understand from scratch