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.
Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 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 Best Website and Software Company in Allahabad