【python4】命名元组

命名元组是一个类,有两种方式来定义命名元组

from collections import  namedtuple
User=namedtuple('userInfo',('name','age','id'))
#实例化命名元组
user1=User('小明','18','01')
print(user1)
print(user1.name)
print(user1.age)
print(user1.id)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_46069582/article/details/113705743