Usingappend()method
Elements can be added to the List by using built-in append() function. Only one element at a time can be added to the list by using append() method, for addition of multiple elements with the append() method, loops are used. Tuples can also be added to the List with the use of append method because tuples are immutable. Unlike Sets, Lists can also be added to the existing list with the use of append() method.
Usinginsert()method
append() method only works for addition of elements at the end of the List, for addition of element at the desired position, insert() method is used. Unlike append() which takes only one argument, insert() method requires two arguments(position, value).
Usingextend()method
Other than append() and insert() methods, there’s one more method for Addition of elements, extend(), this method is used to add multiple elements at the same time at the end of the list.
Note–append()andextend()methods can only add elements at the end.
In order to access the list items refer to the index number.Use the index operator [ ] to access an item in a list.The index must be an integer.Nested list are accessed using nested indexing.
Negative indexing
In Python, negative sequence indexes represent positions from the end of the array. Instead of having to compute the offset as inList[len(List)-3],it is enough to just writeList[-3].Negative indexing means beginning from the end, -1 refers to the last item, -2 refers to the second-last item, etc.
Usingremove()method
Elements can be removed from the List by using built-inremove()function but an Error arises if element doesn’t exist in the set.Remove()method only removes one element at a time, to remove range of elements, iterator is used. Theremove()method removes the specified item.
Note – Remove method in List will only remove the first occurrence of the searched element.
Usingpop()method
Pop()function can also be used to remove and return an element from the set, but by default it removes only the last element of the set, to remove element from a specific position of the List, index of the element is passed as an argument to thepop()method.