When is del useful in python?

前端 未结 21 2399
野趣味
野趣味 2020-11-22 11:58

I can\'t really think of any reason why python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deletin

21条回答
  •  礼貌的吻别
    2020-11-22 12:23

    The "del" command is very useful for controlling data in an array, for example:

    elements = ["A", "B", "C", "D"]
    # Remove first element.
    del elements[:1]
    print(elements)
    

    Output:

    ['B', 'C', 'D']

提交回复
热议问题