Python Code Example: join two lists

In Python it is possible to concatenate a list with another list simply using the + operator.

Code Explanation

LineDescription
1Declaration and initialization of the list firstList with the values 1, 2, 3, 4 and 5
2Declaration and initialization of the list secondList with the values 6, 7, 8, 9 and 10
4In Python, two lists can be concatenated with the + operator
6Outputs joinedList
firstList = [1, 2, 3, 4, 5]
secondList = [6, 7, 8, 9, 10]

joinedList = firstList + secondList

print(joinedList)
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]