自定义命名的元组collections.namedtuple
来源:互联网 发布:上传淘宝的照片不清晰 编辑:程序博客网 时间:2024/06/09 19:52
命名元组与普通的元组一样,有着相同的表现特征,其功能就是可以根据名称引用元组中的项,就像根据索引位置一样,这一功能使我们可以创建数据项的聚集。命名的元组需要引入collections模块,该模块提供了namedtuple()函数用于创建自定义元组:
collections.namedtuple(‘define_tuple_type’,’t_field1 t_field2…’)包含两个字符串类型的参数,第一个是自定义元组的类型名,第二个是自定义元组的各元素的名称,可以用元组名.元素名来访问各元素,代码如下:
import collections
t_name=collections.namedtuple(‘t_type’,’t_field1 t_field2 t_field_3’)
print(t_name)==>_main.t_type(t_name自定义元组的类型是t_type)
t1=t_name(‘ybp’,’xl’,’hello’)
print(t1) ==> t_type(t_field1=’ybp’, t_field2=’xl’, t_field_3=’hello world’)
t1.t_field1 ==> ‘ybp’
t1.t_field2 ==> ‘xl’
t1.t_field3 ==> ‘hello’
阅读全文
0 0
- 自定义命名的元组collections.namedtuple
- 命名元组 collections.namedtuple
- python 2-2 如何为元组中的每个元素命名, 提高程序可读性-collections.namedtuple
- 5.3.5 namedtuple() 创建命名字段的元组结构
- python 命名元组(namedtuple)
- python学习笔记--命名元组(Namedtuple)
- python 命名元组(namedtuple)
- collections模块里的:namedtuple
- Collections -- namedtuple
- 关于Python3的collections.namedtuple和functools.namedtuple的探讨
- Python namedtuple 具名元组
- python模块collections中namedtuple()的理解
- Python的collections模块及namedtuple详解
- python模块collections中namedtuple()的理解
- hackerrank Collections.namedtuple()
- Python HackerRank|Collections.namedtuple(from collections import namedtuple)
- python from collections import namedtuple
- tensorflow学习——collections.namedtuple函数
- git安装
- L1-034. 点赞
- Kickstart Round G 2017 Problem A. Huge Numbers
- 闭包
- nginx 反向代理设置中的proxy_redirect
- 自定义命名的元组collections.namedtuple
- 异常捕获
- VPN网络 私有网络(VPC)
- UVa10084
- mysql 触发器使用及详解
- angularjs之增删改查2
- 这是增删改查的表格
- angular表格添加+查找+修改
- strlen,strcpy,strcat,strcmp,strchr 的模拟实现