Introduction
List concatenation and repetition help you combine lists or repeat their items easily, just like joining or copying groups of things in real life.
Jump into concepts and practice - no test required
list1 + list2 # Concatenates two lists list * n # Repeats the list n times
fruits = ['apple', 'banana'] more_fruits = ['orange', 'grape'] all_fruits = fruits + more_fruits print(all_fruits)
numbers = [1, 2, 3] repeated_numbers = numbers * 3 print(repeated_numbers)
empty_list = [] result = empty_list + [1, 2] print(result)
single_item = [5] repeated_single = single_item * 4 print(repeated_single)
fruits = ['apple', 'banana'] more_fruits = ['orange', 'grape'] print('Before concatenation:', fruits) print('Second list:', more_fruits) all_fruits = fruits + more_fruits print('After concatenation:', all_fruits) numbers = [1, 2, 3] print('Original numbers:', numbers) repeated_numbers = numbers * 3 print('After repetition:', repeated_numbers)
[1, 2] + [3, 4] do in Python?[5, 6] three times?lst1 = [1] lst2 = [2, 3] result = lst1 * 2 + lst2 * 3 print(result)
list_a = [1, 2] list_b = [3, 4] result = list_a * list_b print(result)
fruits = ['apple', 'banana']veggies = ['carrot']