Python list is a data structure which is similar to an array with the support to store data of different datatypes. Python does not support native arrays, instead, it offers lists to do the same in a versatile manner. As most of the elements in Python, a list is also an object and comes with numerous methods for manipulating the data stored in it. Python lists are mutable, ordered sequence of items of different datatypes.
Python List syntax
The items of a list are separated with a comma (,) and are enclosed within square brackets as shown below. A Python list can be stored in a variable for referring in various sections of the program.
#Python list ["apple","orange","mango"] #Storing the list in a variable a = ["apple","orange","mango"]
Python List Methods
Similar to strings, a list can be sliced, append to another list, reversed etc.
|append()||append new items an existing list. The new items will be added to the last position of the list.|
|extend()||Append another list to the end of an existing list.|
|insert()||Insert a new item at a specified index of a list.|
|remove()||Removes the specified item from the list.|
|clear()||Removes all items from the list.|
|count()||Returns the number of occurrences of the specified item.|
|reverse()||Reverses the position of items of the list.|
|len()||Returns the length/size of a list.|