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
18
8
81
9.8K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Answer: [1, 2, 3, 4] y = x means both variables point to the same list (same reference). y.append(4) modifies that shared list. So x also becomes → [1, 2, 3, 4]
English
0
0
11
473
Jeff
Jeff@Jeff72571425107·
@PythonPr x is assign the address of y y appends 4 since 'y' is pointing to the same object the value of 'x' is equal to x concatenated with y x=[1,2,3,4]
English
0
0
4
236
Lalit Aditya
Lalit Aditya@lalit_aditya_·
@PythonPr shallow copy (same reference), so x = [1,2,3,4]
English
0
0
2
205
laso
laso@lasitolas·
@PythonPr [1,2,3,4]...note use of the keyword append and assignment of variables x and y
English
0
0
1
163
@BuildForGe
@BuildForGe@Immanuel_eben08·
@PythonPr the printout will be [1, 2, 3, 4] because x has been assigned to the variable y, so it's like a Shadow form of writing the code
English
0
0
0
16
Paylaş