python中List添加、删除元素的几种方法
发布网友
发布时间:2022-04-06 05:28
我来回答
共1个回答
热心网友
时间:2022-04-06 06:58
add element:
alist = [1, 2, 3]
alist.append(4)
print(alist) # [1, 2, 3, 4]
delete element:
alist.remove(2)
print(alist) # [1, 3, 4]
alist.pop(2)
print(alist) # [1, 3]