w3resource

Python: Append a list to the second list

Python List: Exercise - 24 with Solution

Write a Python program to append a list to the second list.

Example - 1 :

Python: Append a list to the second list

Example - 2 :

Python: Append a list to the second list

Example - 3 :

Python: Append a list to the second list

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:

Flowchart: Append a list to the second list

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.



Follow us on Facebook and Twitter for latest update.