Append function Python
Syntax
The syntax of the append()
method is
list.append(item)
List Append
append() Parameters
The method takes a single argument
item
– an item to be added at the end of the list
Return Value from append()
returns none
Python List Append
myList=[3,5,7,'python'] myList.append(6) print("The appended list is:", myList)
The appended list is: [3, 5, 7, 'python', 6]
Append Multiple Items to List Python
Using Extend
myList=[3,5,7,'python'] myList.extend([2,4,10]) print("The appended list is:", myList)
The appended list is: [3, 5, 7, 'python', 2, 4, 10]
Append multiple elements Python
Using Concatenation
The +
symbol is used for concatenation and merges two list.
myList1=[1, 3, 5, 6] myList2=['python','javascript'] myList3= myList1 + myList2 print("The List is:", myList3)
The List is: [1, 3, 5, 6, 'python', 'javascript']