1. 程式人生 > 其它 >【Python 基礎】二維陣列的例子二

【Python 基礎】二維陣列的例子二

返回:Python基礎 索引頁

希望形成如下的二維陣列:

[Action --1][3]
[Action --2][5]
[Action --3][2]
[Action --4][1]
[Action --5][8]
[Action --6][4]

以列表實現,程式碼如下:

simplist = []

tmpFactor= []
tmpFactor.append("[Action --1]")
tmpFactor.append(3)
simplist.append(tmpFactor)

tmpFactor= []
tmpFactor.append("[Action --2]")
tmpFactor.append(
5) simplist.append(tmpFactor) tmpFactor= [] tmpFactor.append("[Action --3]") tmpFactor.append(2) simplist.append(tmpFactor) tmpFactor= [] tmpFactor.append("[Action --4]") tmpFactor.append(1) simplist.append(tmpFactor) tmpFactor= [] tmpFactor.append("[Action --5]") tmpFactor.append(8) simplist.append(tmpFactor) tmpFactor
= [] tmpFactor.append("[Action --6]") tmpFactor.append(4) simplist.append(tmpFactor) print (simplist)

測試獲得結果如下:

[['[Action --1]', 3], ['[Action --2]', 5], ['[Action --3]', 2], ['[Action --4]', 1], ['[Action --5]', 8], ['[Action --6]', 4]]

返回:Python基礎 索引頁