Remove multiple items from a Python list in just one statement

前端 未结 7 1325
逝去的感伤
逝去的感伤 2020-12-02 06:28

In python, I know how to remove items from a list.

item_list = [\'item\', 5, \'foo\', 3.14, True]
item_list.remove(\'item\')
item_list.remove(5)
相关标签:
7条回答
  • 2020-12-02 07:02

    You Can use this -

    Suppose we have a list, l = [1,2,3,4,5]

    We want to delete last two items in a single statement

    del l[3:]
    

    We have output:

    l = [1,2,3]

    Keep it Simple

    0 讨论(0)
提交回复
热议问题