Post

Python Developer
Python Developer@Python_Dv·
Comment below the output! 😃👇
Python Developer tweet media
English
16
7
80
10K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@Python_Dv Output: B — [[5], [5]] Explanation (short): [[0]] * 2 creates two references to the same inner list. Updating x[0][0] = 5 changes it for both. Result → [[5], [5]]
English
1
0
4
421
Earnest Codes
Earnest Codes@Earnesto037·
@Python_Dv Answer: B The code initializes a list x by repeating the list [0] twice using the * operator. In Python, when a mutable object (like a list) is duplicated this way, both instances within the outer list refer to the same underlying object in memory.
English
1
0
2
335
Earnest Codes
Earnest Codes@Earnesto037·
@Python_Dv Answer: B[[5], [5]]  The code x = [[0]] * 2 creates a list containing two references to the same inner list [0]. This is because multiplying a list with nested objects creates multiple shallow copies, not deep copies.Therefore, x is initialized as [[0], [0]], but
English
0
0
1
273
ANVTech
ANVTech@ANV_Tech·
@Python_Dv The answer is B. Shallow copies strike again! 😅 This is exactly why you use list comprehensions like [[0] for _ in range(2)] instead.
English
0
0
0
34
Saket Kumar
Saket Kumar@SaketKumarX·
@Python_Dv Output : B [[5][5]] ✅ x = [[0]] * 2 --> [[0] [0]] # two references to the SAME inner list x[0][0] = 5 --> [[5][5]] # modifies that single inner list print(x) --> [[5][5]] ✅
English
0
0
0
128
Leigh-2038
Leigh-2038@s_leigh_2038·
@Python_Dv D, error. The second line has a ) with no matching (.
English
0
0
0
145
Paylaş