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.
Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad