List Functions
Method Description Syntax
len() Returns the length of the list len(list)
list() ▪ It takes exactly one optional argument. L=list([iterable object])
▪ Creates an empty list if no argument is passed
append() ▪ It takes exactly one argument. list.append(item)
▪ Add a single element to the end of the list.
▪ If no argument passed, it raises TypeError.
extend() ▪ It takes exactly one argument. list.extend(iterable object)
▪ Adds iterable elements to the end of the list.
▪ If no argument passed, it raises TypeError.
insert() ▪ It takes exactly two arguments. list.insert(index,element)
▪ Inserts an element at a particular index to the list
count() ▪ It takes exactly one argument. list.count(element)
▪ Returns count of the element in the list.
▪ If the element is not in the list, it returns 0.
index() ▪ It takes at least one argument. list.index(element[,start,end])
▪ Returns index of the first occurrence of the element in the list.
▪ If the element is not in the list, it raises the ValueError.
▪ If we do not give start and end then searching starts from index 0 and ends at
length of the string.
del ▪ Used to delete the entire list or the elements using slicing. (i)del L[0:5] (ii) del L[1:9:2]
(iii) del L
remove() ▪ It takes exactly one argument. list.remove(element)
▪ Removes the first matching element(which is passed as an argument) from
the list
▪ If the element is not in the list, it raises the ValueError.
List Functions
Method Description Syntax
pop() ▪ It takes exactly one optional argument. list.pop([index])
▪ It removes element at the given index.
▪ If no argument is passed, it removes the last element from the list. If the
index is not there, it raises IndexError.
reverse() ▪ It takes no argument. list.reverse()
▪ Reverse the list elements.
sort() ▪ It takes exactly one optional argument. list.sort([reverse=True|False])
▪ Sorts elements of the list in ascending order by default.
▪ If the reverse argument is True, the elements will be in the descending order.
sorted() Sorts elements of the list and returns the list, without modifying the original list sorted(list[,reverse])
clear() Removes all items from the list list.clear()
min() It returns the minimum element of the list. min(list)
max() It returns the maximum element of the list. max(list)
sum() It sums the iterable object and returns the sum sum(itearable[,start])