1.

How do you create a Namedtuple in Python?

Answer»

To create a named tuple in Python, FOLLOW these steps:

  • IMPORT the namedtuple class from the collections module.
  • Now, the constructor shall take the name of the named tuple and a STRING CONTAINING the names of the field, SEPARATED by whitespace.
  • The above action shall return a new namedtuple class for the specified fields.
  • To use the new namedtuple, call the new class with all the values (in order) as parameters.


Discussion

No Comment Found