|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想对x[0]进行切片语法,但看起来貌似不行,请各位前辈指点
>>> x
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> x[0][1:0]=1
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
x[0][1:0]=1
TypeError: can only assign an iterable
>>> x[0][1:2]=1
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
x[0][1:2]=1
TypeError: can only assign an iterable
>>> x[0][1:1]=1
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
x[0][1:1]=1
TypeError: can only assign an iterable
你这样对一个不是嵌套的列表也不行啊
- >>> y
- [0, 0, 0]
- >>> y[0:1] = 1
- Traceback (most recent call last):
- File "<pyshell#8>", line 1, in <module>
- y[0:1] = 1
- TypeError: can only assign an iterable
复制代码
增
- >>> x
- [[0, 0, 0], [0, 0, 0]]
- >>> x.append([1,2,3])
- >>> x
- [[0, 0, 0], [0, 0, 0], [1, 2, 3]]
复制代码
删
- >>> del x[2]
- >>> x
- [[0, 0, 0], [0, 0, 0]]
复制代码
改
- >>> x[1][0:1] =[1]
- >>> x
- [[0, 0, 0], [1, 0, 0]]
- >>> x[0]=[1,2,3]
- >>> x
- [[1, 2, 3], [1, 0, 0]]
复制代码
|
|