page contents

什么是namedtuple ?

王昭君 发布于 2022-12-19 10:49
阅读 1929
收藏 0
分类:Python开发
4429
Nen
Nen
- 程序员

Namedtuple能让我们用名称/标签获取一个元组的元素,这里我们使用函数namedtuple(),将其从collections模块中导入。

>>> from collections import namedtuple>>> result=namedtuple('result','Physics Chemistry Maths') #format>>> Ayushi=result(Physics=86,Chemistry=95,Maths=86) #declaring the tuple>>> Ayushi.Chemistry95
请先 登录 后评论