Appending one list to another is a common operation in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to append a list to another list efficiently.
Example 1:
fruits = ['apple', 'banana', 'orange'] more_fruits = ['kiwi', 'mango'] fruits.extend(more_fruits) print(fruits)
Output: [‘apple’, ‘banana’, ‘orange’, ‘kiwi’, ‘mango’]
Example 2:
numbers = [1, 2, 3] more_numbers = [4, 5] numbers += more_numbers print(numbers)
Output: [1, 2, 3, 4, 5]