What will be the output of the following Python code? [code] lst=[3,4,6,1,2] lst[1:2]=[7,8] print(lst) [/code]

Quốc Ân

New member
What will be the output of the following Python code?
Code:
lst=[3,4,6,1,2]
lst[1:2]=[7,8]
print(lst)
A. [3, 7, 8, 6, 1, 2]
B. Syntax error
C. [3,[7,8],6,1,2]
D. [3,4,6,7,8]
 
Answer: a
Explanation: In the piece of code, slice assignment has been implemented. The sliced list is replaced by the assigned elements in the list. Type in python shell to verify.
 

Tìm kiếm

Back
Top