namedtuple Equivalent to a lightweight class , You can also access elements with subscripts .
from collections import namedtuple
User = namedtuple('Person', ['name', 'age', 'gender'])# The first parameter is the tuple name , The second parameter is the name of each element of the tuple
u = User('villa', 33, 'male')# Create a concrete tuple
print(u.name)
print(u[1])
for i in u:
print(i)
print(type(u))
Output :
villa
33
villa
33
male
<class '__main__.Person'>