Pop element from list Python
Ngày đăng:
21/12/2021
Trả lời:
0
Lượt xem:
33
Python - Remove List Items
Previous
Next
Remove Specified ItemThe remove() method removes the specified item. Show ExampleRemove "banana":
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
Remove Specified IndexThe pop() method removes the specified index. ExampleRemove the second item:
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
If you do not specify the index, the pop() method removes the last item. ExampleRemove the last item:
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
The del keyword also removes the specified index: ExampleRemove the first item:
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
The del keyword can also delete the list completely. ExampleDelete the entire list:
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
Clear the ListThe clear() method empties the list. The list still remains, but it has no content. ExampleClear the list content:
thislist = ["apple", "banana", "cherry"]
Try it Yourself »
Previous
Next
|