CBSE Class 12 Computer Science Question 39 of 57

Review of Python Basics — Question 39

Back to all questions
39
Question

Question 34

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

Solution
list1 = eval(input("Enter the first list: "))
list2 = eval(input("Enter the second list: "))
list1.extend(list2)
print("Appended List:", list1)
Output
Enter the first list: [22, 44, 66, 88]
Enter the second list: [10, 30, 50, 70, 90]
Appended List: [22, 44, 66, 88, 10, 30, 50, 70, 90]
Answer

list1
=
eval
(
input
(
"Enter the first list: "
))
list2
=
eval
(
input
(
"Enter the second list: "
))
list1
.
extend
(
list2
)
print
(
"Appended List:"
,
list1
)
Output
Enter the first list: [22, 44, 66, 88]
Enter the second list: [10, 30, 50, 70, 90]
Appended List: [22, 44, 66, 88, 10, 30, 50, 70, 90]