Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 [0]在len(a[0])中表示什么?_Python 2.7_List_Loops_Parameters - Fatal编程技术网

Python 2.7 [0]在len(a[0])中表示什么?

Python 2.7 [0]在len(a[0])中表示什么?,python-2.7,list,loops,parameters,Python 2.7,List,Loops,Parameters,我找到了这段代码,但我无法理解[0]或任何数字的函数 a = [[1,2],[3,4]] b = [[6,3],[5,9]] t = [[0,0],[0,0]] for i in range(len(a)): for j in range(len(b[0])): for k in range(len(b)): t[i][j] += a[i][k] * b[k][j] print t 我对python真的很陌生,因此,如果这是一个愚蠢的问题

我找到了这段代码,但我无法理解[0]或任何数字的函数

a = [[1,2],[3,4]]
b = [[6,3],[5,9]]
t = [[0,0],[0,0]]

for i in range(len(a)):

    for j in range(len(b[0])):

        for k in range(len(b)):
             t[i][j] += a[i][k] * b[k][j]
print t

我对python真的很陌生,因此,如果这是一个愚蠢的问题,我很抱歉。

a
是一个列表时,
a[0]
将返回
a
的第一个元素(列表从0开始)。

在你的情况下,
a[0]=[1,2]
b[0]=[6,3]
b[1]=[5,9]
a[0][0]=1
尝试你不懂的东西(边走边读文档)

给定

我们得到

>>> len(a)
2
因此,
a
中有两个东西,我们可以通过索引到
a
如果我们走得太远,就会出现错误:

>>> a[0]
[1, 2]
>>> a[1]
[3, 4]
>>> a[2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
甚至

>>> len(b[0])
2
您有一些列表。对它们进行索引将返回一个列表

简单回顾一下,
a[0]
是一个列表
[1,2]
。我们可以得到其中任何一个元素,如果我们走得太远,就会得到一个错误:

>>> a[0][0]
1
>>> a[0][1]
2
>>> a[0][2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

您可以将每个列表视为矩阵的一部分,第一个索引给出行,第二个索引给出列:


列表的第一个元素。。。订阅查找列表索引、订阅和/或
\uuuu getitem\uuuu
<代码>[0]
获取列表的第一个元素。是的,我知道它执行矩阵乘法:)。非常感谢您抽出时间回答:)谢谢您回答问题:)
>>> len(b[0])
2
>>> a[0][0]
1
>>> a[0][1]
2
>>> a[0][2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> print t
[[16, 21], [38, 45]]