How to append element in the list using Python?

There may arise some situations where we need to add or append an element at the end of a list. We’ll use append() method in Python which adds an item to the end of the list.
The length of the list increases by one.
list.append(item)
The single parameter item is the item to be added at the end of the list. The item can be number, string, another list, dictionary etc.
We can append an element at the end of a list using the append() method. The element is appended and the size of the list is increased.
 Live Demo
colors=["red","blue","black"]
print("List",colors)
print("Size of list", len(colors))
colors.append("white")
print("Updated list",colors)
print("Size of updated list",len(colors))
List ['red', 'blue', 'black']
Size of list 3
Updated list ['red', 'blue', 'black', 'white']
Size of updated list 4
The append() method can also add another list to the end of the list.
 Live Demo
colors=["red","blue","black"]
print("List",colors)
fruits=["apple","grapes","mango"]
colors.append(fruits)
print("Updated list",colors)
List ['red', 'blue', 'black']
Updated list ['red', 'blue', 'black', ['apple', 'grapes', 'mango']]
The extend() method also adds elements at the end of the list. This is different from append(). The extend() method iterates over its argument and adds each element into the list. The length of the list increases by the length of elements of the argument.
list.extend(iterable)
The iterable can be a string or another list.
The string is an iterable. Thus, extending a list with a string will append all the characters of the string at the end of the list. The length of the list increases by the length of the string in the argument.
 Live Demo
colors=["red","blue","black"]
print("List",colors)
print("Size of list", len(colors))
colors.extend("white")
print("Updated list",colors)
print("Size of updated list",len(colors))
List ['red', 'blue', 'black']
Size of list 3
Updated list ['red', 'blue', 'black', 'w', 'h', 'i', 't', 'e']
Size of updated list 8
The list is iterable. Extending list with another list will append all the elements of the argument list at the end of the existing list. The size of the list increases by the size of the list in the argument.
 Live Demo
colors=["red","blue","black"]
print("List",colors)
print("Size of list", len(colors))
colors2=["white","pink","orange"]
colors.extend(colors2)
print("Updated list",colors)
print("Size of updated list",len(colors))
List ['red', 'blue', 'black']
Size of list 3
Updated list ['red', 'blue', 'black', 'white', 'pink', 'orange']
Size of updated list 6
The append() and extend() have different functionalities.
The append() and extend() have different functionalities.
The append() method adds the argument as a single element whereas the extend() iterates over the argument and adds each element at the end of the list.
The append() method adds the argument as a single element whereas the extend() iterates over the argument and adds each element at the end of the list.
The append() method increases the length of the list by one whereas the extend() increases the length of the list by length of the argument element.
The append() method increases the length of the list by one whereas the extend() increases the length of the list by length of the argument element.
The append() has constant time complexity i.e. O(1) whereas extend() has time complexity O(k) where k is the length of the argument.
The append() has constant time complexity i.e. O(1) whereas extend() has time complexity O(k) where k is the length of the argument.