Python List is a collection of ordered and changeable it allows duplicate members. The list is like a container used to store multiple data in same line. In list of python is used to store collection of object types. The next two types are dictionaries and tuple. Python list do work of most of collection of the data structures and don’t worry of manually creating them. Lists are like the arrays, and are declared in other languages. They are not homogeneous always this makes it most powerful tool in Python. The single list may contain Data types are like Integers, objects, as well as strings it used for the implementation of stacks and queues The list in Python has fixed count and has an order.
The elements in a list are indexed according to a sequence and indexing of a list is done with 0 the first index.
Each element in the list has its definite place in the list it allows duplicating of elements in the list.
Lists are a useful tool for preserving a sequence of data and further iterating over it.
In python list is created by placing elements inside a square bracket [], separated by commas.
List in python are used to store collection of items.
You can recognize list by their square bracket [and] that hold.
Python list are the c array inside python interpreter and act like array of pointers.
e.g:-
thislist = ["mango", "apple", "cherry"]
print(thislist[2])
O/p:-
cherry
e.g:-
thislist = ["mango", "apple", "cherry"]
print(thislist[-1])
O/p:-
cherry
You specify a range of indexes by specify where to start and where to end the range.
When specifying a range, the return value will be in the new list with the specified items.
e.g:-
thislist = ["Banana", "mango", "apple", "orange", "kiwi", "melon", "mango"]
print(thislist[1:5])
O/p:-
[‘mango’,‘apple’,’orange’,’kiwi’]
#This will return the items from position 1 to 5.
#Remember that the first item is position 0,
#and note that the item in position 5 is NOT included
e.g:-
thislist = ["apple", "kaju", "cherry"]
thislist[1] = "banana"
print(thislist)
O/p:-
[‘mango’,’cherry’,’banana’]
The explanation is adding new item by replacing the original one is done here.