List in python
The most important data structure in every language is a list which is allocated in sequence. Each listed value have their own index starting from zero.
Basically, there are 6 inbuilt types in Python in which tuple and list are very imperative. There is various kind of operation which you can perform in the list like slicing, insertion, deletion, updating, adding and multiplication, in fact, there are a lot of methods provided by Python which is very helpful to code it.
list1 = ['ravi', 'kavi', 19, 200];
list2 = [1, 2, 3, 4, 5, 7 ];
list3 = ["a", "b", "c", "d"]
List:
The list is a special type of data type in Python which is separated by, and we can accept the values of different data types.
For example:
mylist = ["MainVPS ", "basically ", "cherish "]
print(type(mylist))
How to access the value in the list?
In order to access the value of the list, you need to use the square brackets along with the index position.
For instance:
this1 = ["apple", "graphs ", "cherry"]
print(this1[1])
this2 = ["apple", "banana", "cherry", "melon", "mango"]
print(thislist[1:5])
How to update the values on the list?
You can update the values by using slicing to the left of the side of the assignment operator and you can add the values to the list by append ().
For example:
titlist = ["apple", "banana", "cherry"]
titlist[1] = "mango"
print(titlist)
How to delete the element from the list?
In Python, you can delete the element using the del keyword. There is also another method to delete the values from the list that is remove ().
For example:
Numw = ["apple", "banana", "cherry"]
Numw.remove("cherry")
print(Numw)
