List Methods in Python

List Methods in Python

List methods in Python are used to manipulate list objects and used to retrieve some insights from them. Before describing these methods, one should know what lists are. A list is a sequence of elements which mutable and changeable and contain different types of objects as elements. There are a number of methods and functions of list available and they are provided below in the form of a table.

 

List Methods and Functions  Description
append() It is a method and is used to add an element which is passed as an argument to the end of the list object.
clear() It is a method and is used to clear out all the elements from the list object. It means that after calling this method, the specified list object will be empty and have no elements in it.
copy() It is a method and is used to create a copy of the list object.
count() It is a method and returns the number of occurrences of a specified element in the list object.
extend() It is a method and is used to add an element or an iterable (more than one elements) that is passed as an argument at the end of the list object.
index() It is a method and returns the index number of the first occurrence of the specified element in the list object.
insert() It is a method and is used to add the specified element at the specified position in the list object.
pop() It is a method and deletes the last element or element at the index if mentioned from the list object.
remove() It is a method and deletes the first occurrence of the specified element from the list object.
reverse() It is a method and reverses the order of all the elements of the list object.
sort() It is a method and sorts the elements of the list object in either increasing or decreasing order on the basis of the specified sorting criteria.
len() It is a function and returns number of elements the list object consists of.
list() It is a function/constructor and is used to create a list from an iterable like a tuple, list, etc.
Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *