Difference between del, remove and pop on lists

前端 未结 12 2172
北海茫月
北海茫月 2020-11-22 04:20
>>> a=[1,2,3]
>>> a.remove(2)
>>> a
[1, 3]
>>> a=[1,2,3]
>>> del a[1]
>>> a
[1, 3]
>>> a= [1,2,3]
>         


        
12条回答
  •  粉色の甜心
    2020-11-22 04:32

    Already answered quite well by others. This one from my end :)

    Evidently, pop is the only one which returns the value, and remove is the only one which searches the object, while del limits itself to a simple deletion.

提交回复
热议问题