python 如何为 tuple 中每个元素命名?

from collections import namedtuple


Student = namedtuple('Student', ['name', 'age', 'gender', 'email'])
s = Student('Tom', 16, 'male', '[email protected]')
# s 为内置元组带子类
print(s.name)
# 输出为:'Tom'
print(s.age)
# 输出为:16

你可能感兴趣的:(python 如何为 tuple 中每个元素命名?)