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 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz