【问题标题】:How to print last deleted element from the list?如何从列表中打印最后删除的元素?
【发布时间】: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


    【解决方案1】:

    pop 函数返回并删除列表中的一项。所以你可以这样做:

    l=[1,2,3,4]
    print(l.pop(0))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2021-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多