Report Bug

Qus

What will be the output of the following Python code?

places = ['Bangalore', 'Mumbai', 'Delhi']
places1 = places
places2 = places[:]
places1[1]="Pune"
places2[2]="Hyderabad"
print(places)
Qus

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

places = ['Bangalore', 'Mumbai', 'Delhi']
places1 = places
places2 = places[:]
places1[1]="Pune"
places2[2]="Hyderabad"
print(places)


A. [‘Bangalore’, ‘Pune’, ‘Hyderabad’]
B. [‘Bangalore’, ‘Pune’, ‘Delhi’]
C. [‘Bangalore’, ‘Mumbai’, ‘Delhi’]
D. [‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]


Solution
B. [‘Bangalore’, ‘Pune’, ‘Delhi’]



Explanation
places1 is an alias of the list places. Hence, any change made to places1 is reflected in places. places2 is a copy of the list places. Thus, any change made to places2 isn’t reflected in places.
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