In this code example, we add all list entries to another list. For this we use the extend()
method.
Line | Description |
---|---|
1 | Declaration and initialization of the list firstList with the values 1, 2, 3 and 4. |
2 | Declaration and initialization of the list secondList with the values 5, 6, 7 and 8. |
4 | The extend() method extends one list with another. In this case, the second list is appended to the first. |
6 + 7 | With the for loop each list element of firstList is output |
firstList = [1, 2, 3, 4]
secondList = [5, 6, 7, 8]
firstList.extend(secondList)
for i in firstList:
print(i, end=" ")
1 2 3 4 5 6 7 8