Professional Documents
Culture Documents
List Methods in Python | Set 1 (in, not in, len(), min(), max()…)
More methods are discussed in this article.
1. del[a : b] :- This method deletes all the elements in range starting from index ‘a’ till ‘b’
mentioned in arguments.
2. pop() :- This method deletes the element at the position mentioned in its arguments.
Output:
Output:
7. extend(b) :- This function is used to extend the list with the elements present
in another list. This function takes another list as its argument.
8. clear() :- This function is used to erase all the elements of list. After this
operation, list becomes empty.
# Python code to demonstrate the working of
# extend() and clear()
# initializing list 1
lis1 = [2, 1, 3, 5]
# initializing list 1
lis2 = [6, 4, 3]
# using extend() to add elements of lis2 in lis1
lis1.extend(lis2)
# displaying list after sorting
print ("List elements after extending are : ", end="")
for i in range(0, len(lis1)):
print(lis1[i], end=" ")
print ("\r")
# using clear() to delete all lis1 contents
lis1.clear()
# displaying list after clearing
print ("List elements after clearing are : ", end="")
for i in range(0, len(lis1)):
print(lis1[i], end=" ")
Output: