python 命名元祖

2019-08-15  本文已影响0人  足__迹
平常使用的数据类型

散列类型内部存储逻辑
集合的值和字典的键,通过计算哈希值存储到相关位置,所以字典和集合中的值必须是唯一的

from  collections import namedtuple

studeng = namedtuple('studengt', ['name', 'age', 'gender'])
print(type(studeng))     #判断类型是一个类
s1 = studeng('小明', 18, '男')
print(type(s1))          #返回一个类
print(s1.name)   #通过对应的字段取值
print(s1[0])     #通过下标取值

优点: 查询速度更快

上一篇 下一篇

猜你喜欢

热点阅读