[英]Extract tuple from list
我有这个列表: [(hello(21,15),'now')] 列表中的一个元组,我想以输出的方式提取元组
(你好(21,15,'现在')
做就是了:
lst[0]
获取自列表索引从0
开始的第一个元素
>>> a = [1,2,3]
>>> a[0]
1
>>> a[2]
3
>>> a = [(hello(21,15),'now')]
>>> a[0]
(hello(21,15), 'now')
如果您还想获得'now'
文本,请执行以下操作:
>>> a[0][1]
'now'
如果您想从列表中获取一系列值,您可以使用[:]
,如下所示:
>>> a = [1,2,3,4,5,6,7,8]
>>> a[2:6] #this gets the elements from index 2 to 5
[3,4,5,6]
>>> a[-1] #this gets the last element of the list
8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.