How to Remove Item or Clear List in Python?
Posted 2022-10-13 09:34:19
0
66
remove()
method:
The remove()
method removes the specified item.
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
pop()
method:
The pop()
method removes the specified index. If you do not specify the index, the pop()
method removes the last item.
thislist = ["apple", "banana", "cherry"]
thislist.pop(1)
print(thislist)
del
keyword:
The del
keyword also removes the specified index. The del
keyword can also delete the list completely.
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)
clear()
method:
The clear()
method empties the list. The list still remains, but it has no content.
thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)
Zoeken
Categorieën
- Information Technology
- Office Equipment and Supplies
- Cars and Trucks
- Persons
- Books and Authors
- Tutorials
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Spellen
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Other
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Read More
How Long Does Hydrocodone Stay in Your System?
Hydrocodone is in a class of medications called opiate analgesics in a class of medications...
© 2025 Omaada - A global social and professionals networking platform
Dutch
