CBSE Class 11 Informatics Practices
Question 32 of 80
Lists in Python — Question 10
Back to all questions 10
Question Consider the following code:
>>>A = [10, 20, 30, 40]
>>>B = A.copy()
>>>A[2] = 50
>>>BWhich of the following will be the elements of list A and B?
- A = [10, 20, 50, 40]
B = [10, 20, 30, 40] - A = [10, 20, 30, 40]
B = [10, 20, 50, 40] - A = [10, 20, 30, 40, 50]
B = [10, 20, 50, 40] - A = [10, 20, 40]
B = [10, 20, 50, 40]
A=[10, 20, 50, 40]
B=[10, 20, 30, 40]
Reason — The code initializes list A with elements [10, 20, 30, 40]. It then creates a copy of list A named list B using the copy() method. Subsequently, the third element of list A is modified to 50 using A[2] = 50. At this point, B is still [10, 20, 30, 40], because it's a separate list from A. The copy() method does not modify the original list or the modifications made in the new list will not be reflected to the base list.