Working with python means basic three operations on lists i.e. appending, updating and deleting elements in list.
Appending elements to a list:-
It means adding elements at the end of the list. We can do this with the help of a function append().
e.g.,
a=[10, 12, 22, 26] a.append(30) print(a)
Output- [10,12,22,26,30]
Updating elements to a list:-
To update or change an element in a list in place, we have to assign new value to the element’s index in the list.
e.g.,
a=[10, 12, 16, 20, 24] a[2]=18 print(a)
Output- [10, 12, 18, 20, 24]
Deleting elements from a list:-
For deleting elements from a list we use del() function in python. We write the index of the element we have to delete in bracket and then delete it.
e.g.,
a=[1, 2, 3, 4, 5, 6] del a[3] print(a)
Output- [1, 2, 3, 5, 6]
This is all about working with lists in python.