如何使用索引找到二维数组的元素?Python [英] How do you find a element of a two dimensional array using the index? python

查看:27
本文介绍了如何使用索引找到二维数组的元素?Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

a = [[1,2,3],[4,5,6],[7,8,9]

我应该怎么做才能在 a 中找到 5?

what should I do to find 5 in a?

我尝试使用:

a[[2],[2]]

但它不起作用.

推荐答案

a 中的每个子列表都可以使用从 0 开始的索引来访问.即:

Each sublist in a can be accessed with an index starting at 0. ie:

print a[0] # = [1,2,3]

对每个子列表中的元素应用相同的索引原则

you apply the same index principle to the elements within each sublist

     |  0  | |  1  | |  2  |
a = [[1,2,3],[4,5,6],[7,8,9]] 
index 0 1 2   0 1 2   0 1 2

print a[1][1] # = 5

这篇关于如何使用索引找到二维数组的元素?Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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