Elements in a list are changeable or mutable that means elements can be deleted, adding new element at the end of a list or updating current value of element with new one.
Append means adding new element at the end of list. We can use append() method to perform this task.
Below is the cars list.
cars = ['Tata','Ford','Renault','Ferrari','Volkwagen'] print(cars)
OUTPUT
['Tata', 'Ford', 'Renault', 'Ferrari', 'Volkwagen']
We will add new element ‘Toyota’ at the end of the above list using append method.
Syntax for append() method :- list_name.append(element)
cars.append('Toyota') print(cars)
OUTPUT
['Tata', 'Ford', 'Renault', 'Ferrari', 'Volkwagen', 'Toyota']
Above output shows new element ‘Toyota’ has been added at the end of list.
Now in the below example, we have created numbers list and then appended new element in the list.
numbers = [10,20,30,40,50] print(numbers) numbers.append(60) print(numbers) numbers.append(70) print(numbers)
OUTPUT
[10, 20, 30, 40, 50]
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60, 70]