Report Bug

Qus

What will be the output of the following Python code?

lst=[3,4,6,1,2]
lst[1:2]=[7,8]
print(lst)
Qus

निम्नलिखित Python कोड का आउटपुट क्या होगा?

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]


Solution
A. [3, 7, 8, 6, 1, 2]



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.
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad