您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页Python collections模块--nametuple

Python collections模块--nametuple

来源:二三娱乐

nametuple 可命名元祖

nametuple 为元祖中每个位置分配含义,可以在使用常规元祖的地方使用,并且添加了通过名称而不是位置索引访问字段的功能。

In [97]: Mytuple = collections.namedtuple('mytuple', ['x','y'])

In [98]: Mytuple(1,2)
Out[98]: mytuple(x=1, y=2)

In [101]: n = Mytuple(1,2)

In [102]: n
Out[102]: mytuple(x=1, y=2)

In [103]: n.x
Out[103]: 1

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务