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
20
7
47
6.6K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Answer: C — [1, 2, 3]. b = a creates a reference to the same list, not a copy. b.append(3) mutates the shared object, so a also reflects the change.
English
0
0
1
431
Python Tech
Python Tech@PythonTech43716·
@PythonPr C) [1,2,3] is the right answer Because both list a,b are referencing the same object if we append anything in one list and same has been updated in another list.
English
0
0
1
212
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr option c . lists are mutable so its values can be modified. i don't dig into deeper .
English
0
0
0
92
Jeff
Jeff@Jeff72571425107·
@PythonPr ans: C a = [1,2] b = a # sets address b = a same object b.append(3) # modifying b your changing a print(a,id(a),id(b)) # objects have the same ids Output: [1, 2, 3] 133898372286912 133898372286912
English
0
0
0
34
Paylaş