Built-in List Functions & Methods in Python

PythonServer Side ProgrammingProgramming

Python includes the following list functions −

Sr.NoFunction with Description
1cmp(list1, list2)
Compares elements of both lists.
2len(list)
Gives the total length of the list.p>
3max(list)
Returns item from the list with max value.
4min(list)
Returns item from the list with min value.
5list(seq)
Converts a tuple into list.

Python includes following list methods

Sr.NoMethods with Description
1list.append(obj)
Appends object obj to list
2list.count(obj)
Returns count of how many times obj occurs in list
3list.extend(seq)
Appends the contents of seq to list
4list.index(obj)
Returns the lowest index in list that obj appears
5list.insert(index, obj)
Inserts object obj into list at offset index
6list.pop(obj=list[-1])
Removes and returns last object or obj from list
7list.remove(obj)
Removes object obj from list
8list.reverse()
Reverses objects of list in place
9list.sort([func])
Sorts objects of list, use compare func if given
raja
Published on 28-Jan-2020 12:40:01
Advertisements