20
loading...
This website collects cookies to deliver better user experience
# list of integers
number_list = [1, 2, 3, 4, 5]
# example of a list containing different data types
random_list = [1, “apple”, 4, ball”, 7, 9, True]
# How to concatenate lists using the ‘*’ operator in Python
list_one = [11, 12, 13]
list_two = [14, 15, 16]
list_three = [*list_one *list_two]
print(list_three)
[11, 12, 13, 14, 15, 16]
# Python concatenate lists using the ‘+’ operator in Python
list_one = [11, 12, 13]
list_two = [14, 15, 16]
answer = list_one + list_two
print(“The concatenated list is:\n” + str(answer))
[11, 12, 13, 14, 15, 16]
# How to concatenate lists using the append() function in Python
list_one = [9, 8, 7]
list_two = [6, 5, 4]
for element in list_two:
list_one.append(element)
print(list_one)
[9, 8, 7, 6, 5, 4]
# How to concatenate lists using the extend() function in Python
list_one = [1, 2, 3]
list_two = [4, 5, 6]
list_one.extend(list_two)
print(list_one)
[1, 2, 3, 4, 5, 6]