返回: 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基础 索引页
来源:https://www.cnblogs.com/gaojian/p/15974440.html
本站部分图文来源于网络,如有侵权请联系删除。