有其他的方法来做到这件事吗?

12 浏览
0 Comments

有其他的方法来做到这件事吗?

这个问题已经有了答案

如何通过索引从列表中删除元素

是否有另一种方式,而不使用函数pop来做这件事?

Input :a_list = [1,2,3,4,5,6,7]
a_list.pop(1)
Output : a_list = [1,3,4,5,6,7] 

我尝试了一些东西,但在我的尝试之后它显示 TypeError:\'list\'对象不可调用

admin 更改状态以发布 2023年5月21日
0
0 Comments

您可以使用切片:

a_list = [1,2,3,4,5,6,7]
print(a_list)
a_list = a_list[:1] + a_list[2:]
print(a_list)

0
0 Comments

\n\n你可以使用 del 关键字来实现它:\n

a_list = [1,2,3,4,5,6,7]
del a_list[1]
print(a_list)  # [1, 3, 4, 5, 6, 7]

0