python remove pop

>>> help(list.remove)
Help on method_descriptor:

remove(...)
    L.remove(value) -- remove first occurrence of value.
    Raises ValueError if the value is not present.

 

刪除第一個出現的待刪除值。

 

>>> y=[1,0,2,0,3,0,4,0]
>>> y
[1, 0, 2, 0, 3, 0, 4, 0]
>>> y.remove(y[5])
>>> y
[1, 2, 0, 3, 0, 4, 0]

 

>>> help(list.pop)
Help on method_descriptor:

pop(...)
    L.pop([index]) -> item -- remove and return item at index (default last).
    Raises IndexError if list is empty or index is out of range.

 

list.pop()刪除成員,刪除第i個成員

 

>>> y=[1,0,2,0,3,0,4,0]
>>> y
[1, 0, 2, 0, 3, 0, 4, 0]
>>> y.pop(5)
0
>>> y
[1, 0, 2, 0, 3, 4, 0]
>>>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章