Python: Append a list to the second list
Append One List to Another
Write a Python program to append a list to the second list.
Example - 1 :
Example - 2 :
Example - 3 :
Sample Solution:
Python Code:
# Define a list 'list1' containing numeric elements
list1 = [1, 2, 3, 0]
# Define another list 'list2' containing string elements
list2 = ['Red', 'Green', 'Black']
# Concatenate 'list1' and 'list2' to create a single list 'final_list'
final_list = list1 + list2
# Print the 'final_list,' which contains elements from both 'list1' and 'list2'
print(final_list)
Sample Output:
[1, 2, 3, 0, 'Red', 'Green', 'Black']
Flowchart:
Python Code Editor:
Previous: Write a Python program to flatten a shallow list.
Next: Write a Python program to select an item randomly from a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics