Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
28
10
99
11.6K
Jenny
Jenny@JennyTheDev·
@PythonPr b. [1, 2, 3, 4] .copy() creates a shallow copy, so y is independent. Only x gets the append. The real quiz is remembering this at 2am during a production bug 💀
English
2
0
6
881
PerPeet
PerPeet@PPernyesz·
@PythonPr The answer is a), because the script copied first x to y. Then add 4 to x, and y is the original x. If you print x, the value will be [1,2,3,4].
English
0
0
1
452
Hermanos
Hermanos@jaymo_Marubu·
@PythonPr [1, 2, 3] append affects x so y remains the same as x copy.
English
0
0
1
277
Ola Di Gbolu
Ola Di Gbolu@ola_digbolu·
@PythonPr What if y = x, will it be same as copy() or y mutate x
English
0
0
0
76
recorp
recorp@recorpzero·
@PythonPr Copy is a "copy" of the values or a "copy" of the memory of the x?
English
0
0
0
195
Paylaş