✏️ Explanatory Question
The append() and extend() methods are used to add elements to a list in Python, but they behave differently.
The append() method adds a single item to the end of the list:
list1 = [1, 2, 3]
list1.append(4)
print(list1)
# Output:
# [1, 2, 3, 4]
The extend() method, on the other hand, adds multiple elements to the end of the list, by extending the list with another list:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
# Output:
# [1, 2, 3, 4, 5, 6]
So, in summary:
append() adds a single item to the end of the list.extend() adds multiple items to the end of the list, by extending the list with another list.