代码之家  ›  专栏  ›  技术社区  ›  Elementary

在python中从list<item>中删除list-item后的行为

  •  0
  • Elementary  · 技术社区  · 7 年前

    在一些程序语言中,例如php,删除一个项不会自动重新索引数组,我想知道在删除一个带有 del()

    3 回复  |  直到 7 年前
        1
  •  1
  •   Patrick Haugh    7 年前

    l = ['a', 'b', 'c']
    del l[1]
    print(l)  # ['a', 'c']
    print(l[1]) # c
    
        2
  •  0
  •   zgoda    7 年前

        3
  •  0
  •   prasanna    7 年前

       l = [1, 2, 3, 4, 5, 6]
       del l[2]
       l