A list is a data structure, or it can be considered a container that can be used to store multiple data at once. The list will be ordered and there will be a definite count of it. The elements are indexed according to a sequence and indexing is done with 0 as the first index.
To create a list you separate the elements with a comma and enclose them with a bracket””.
a=["Python", "C++", "C", "Java"] print(a)
We can create a two dimensional list. This is done by nesting a list inside another list.
a=[['1', '2'], ['3', '4']] print(a)
Some basic function to modify list are:-
- list.append() – This function will add another element to the list at the end.
- list.insert() – This will add another element to the list at the given index, shifting the elements greater than the index one step to the right.
lst= lst.insert(index_number, "Element_name")
- list.pop() – This function will remove the last element from the list. If the index is provided, then it will remove the element at the particular index.
This is all about lists in python.