حذف آیتم(Remove Item)

روش های مختلفی برای حذف موارد از لیست وجود دارد:




مثال


The remove() method removes the specified item:



thislist = ["apple", "banana", "cherry"]

thislist.remove("banana")

print(thislist)





مثال


The pop() method removes the specified
index, (or the last item if index is not specified):



thislist = ["apple", "banana", "cherry"]

thislist.pop()

print(thislist)





مثال


The del keyword removes the specified
index:



thislist = ["apple", "banana", "cherry"]

del
thislist[0]
print(thislist)





مثال


The del keyword can also delete the list
completely:



thislist = ["apple", "banana", "cherry"]

del
thislist





مثال


The clear() method empties the list:



thislist = ["apple", "banana", "cherry"]

thislist.clear()
print(thislist)