目录
1.初始化
2.增
3.删
4.改
5.查
1.初始化
print([[1,2],[2,3]]+[1,2])
# [[1, 2], [2, 3], 1, 2]
print([[1,2],[2,3]]+[[1,2],[2,4]])
# [[1, 2], [2, 3], [1, 2], [2, 4]]
2.增
# 末尾追加
t = [1, 2, 3]
t1 = t.append([4])
print(t)#t [1, 2, 3, [4]]
print(t1)#t1 None
t = [1, 2, 3]
t2 = t + [4]
print(t) # t [1, 2, 3]
print(t2) # t2 [1, 2, 3, 4]
t = [1,2,3]
t.extend([4])
print(t) # [1, 2, 3, 4]
3.删
t = [1, 2, 3]
del t[1]
print(t) # [1, 3]
t = [1, 2, 3]
print(t.pop()) # 3
print(t) # [1, 2]
t = [1, 2, 3]
print(t.pop(1)) # 2
print(t) # [1, 3]
t = [1, 2, 3, 1, 2, 2]
print(t.remove(1)) # None
print(t) # [2, 3, 1, 2, 2]
t.clear()
print(t) # []
4.改
t = [1, 2, 3]
t.reverse()
print(t) # [3, 2, 1]
t = [1]
t = t * 3
print(t) # [1, 1, 1]
t = [3, 2, 1]
t[2] = 3
print(t) # [3, 2, 3]
t = [3, 2, 1]
t[1:3] = [4]
print(t) # [3, 4]
5.查
|