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]]
The question is, how would I print just the value b1?
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]]
The question is, how would I print just the value b1?
To access b1
, do this:
print array[1][0]
See an example:
>>> array=[['a1','a2','a3','a4'],['b1','b2','b3','b4'],['c1','c2','c3','c4']]
>>> array[1]
['b1', 'b2', 'b3', 'b4']
>>> array[1][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
).