数组内的数组? [英] Array within an array?

查看:77
本文介绍了数组内的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Python数组中的数组中调用元素.例如:

I'm trying to call up an element from an array within an array in Python. For example:

array = [[a1,a2,a3,a4], [b1,b2,b3,b4], [c1,c2,c3,c4]]

问题是,我怎么只打印值b1?

The question is, how would I print just the value b1?

推荐答案

要访问b1,请执行以下操作:

To access b1, do this:

print array[1][0]

查看示例:

>>> array=[['a1','a2','a3','a4'],['b1','b2','b3','b4'],['c1','c2','c3','c4']]
>>> array[1]
['b1', 'b2', 'b3', 'b4']
>>> array[1][0]
'b1'
>>>

基本上,您要在位置1的array索引(返回b列表),然后在位置0的那个索引(返回b1).

Basically, you are indexing array at position 1 (which returns the b list), and then indexing that list at position 0 (which returns b1).

这篇关于数组内的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆