如何在python中使用循环向空矩阵添加行?

如何在python中使用循环向空矩阵添加行?,python,Python,我的尝试: matrix=[[]] if my conidtion is filled: matrix+=([[val1],[val2],[val3]]) print matrix 其中,val1、val2和val3随着我的if循环的每次迭代而变化。使用列表。追加 Ex: matrix=[] if my conidtion is filled: matrix.append([val1, val2, val3]) print matrix 使用list.

我的尝试:

matrix=[[]]
if my conidtion is filled:
     matrix+=([[val1],[val2],[val3]])
     print matrix

其中,val1val2val3随着我的if循环的每次迭代而变化。

使用
列表。追加

Ex:

matrix=[]
if my conidtion is filled:
     matrix.append([val1, val2, val3])
     print matrix

使用
list.append

Ex:

matrix=[]
if my conidtion is filled:
     matrix.append([val1, val2, val3])
     print matrix