编程语言
首页 > 编程语言> > 【Python 基础】修改二维数组的例子

【Python 基础】修改二维数组的例子

作者:互联网

返回: Python基础 索引页

对于如下的二维数组:

[Action --1], 0
[Action --2], 0


将其改为:

[Action --1], 1
[Action --2], 0

 

再改为:

[Action --1], 2
[Action --2], 0


代码如下:

mylist = []

myfactor01= []
myfactor01.append("[Action --1]")
myfactor01.append(0)

mylist.append(myfactor01)
myfactor01= []

myfactor01.append("[Action --2]")
myfactor01.append(1)

mylist.append(myfactor01)
myfactor01= []

##change the mylist[0][1]

tmplist = mylist[0]
tmplist[1] = 1

tmplist = []

mytmp = mylist[0]
print (mytmp)
print (mytmp[1])

mytmp=[]

print (mylist)
print (mylist[0][1])

mylist[0][1] = 2

print (mylist)

输出结果如下:

>>> print (mytmp[1])
1
>>>
>>> mytmp=[]
>>>
>>> print (mylist)
[['[Action --1]', 1], ['[Action --2]', 1]]
>>> print (mylist[0][1])
1
>>>
>>> mylist[0][1] = 2
>>>
>>> print (mylist)
[['[Action --1]', 2], ['[Action --2]', 1]]
>>>

返回: Python基础 索引页

 

标签:mylist,Python,print,--,二维,数组,Action,myfactor01,append
来源: https://www.cnblogs.com/gaojian/p/15974440.html