+ 1

Can someone explain how Python executes this code...

Input: a = [[1, 2]]*4 a[1][1] = 5 print(a) Output: [[1, 5], [1, 5], [1, 5] [1, 5]] I was expecting [[1, 2], [1, 5], [1, 2] [1, 2]] as output.

26th Jun 2020, 3:54 PM
Jolomi Tosanwumi
2 Respostas
+ 2
Great resource 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥. It cleared the air on variables, naming, references and addresses. Although it didn't explicitly answer my question, but it has demystified the mystery of what goes on underneath the hood in Python.
26th Jun 2020, 6:22 PM
Jolomi Tosanwumi
+ 1
Address allocation maybe
26th Jun 2020, 4:22 PM
Itachi
Itachi - avatar