【发布时间】:2023-02-07 16:16:59
【问题描述】:
l=[1,2,3,4]
del l[0]
print(l)
#del l[0]
#want to print this number whenever it will be deleted from the list
如何打印列表中最后删除的元素?
【问题讨论】:
标签: python python-3.x list
l=[1,2,3,4]
del l[0]
print(l)
#del l[0]
#want to print this number whenever it will be deleted from the list
如何打印列表中最后删除的元素?
【问题讨论】:
标签: python python-3.x list
pop 函数返回并删除列表中的一项。所以你可以这样做:
l=[1,2,3,4]
print(l.pop(0))
【讨论】: