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
11
125
11.6K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: b ([10, 2, 3]). The trap: y = x doesn't copy the list! Lists are like boxes with name tags. y = x puts both tags (x and y) on the same box. y[0] = 10 changes the box, so both tags reflect the change. For beginners: To create a separate box, use y = x.copy().
English
0
0
0
528
Caleb Sibanda
Caleb Sibanda@2kdarki·
@PythonPr B. [10, 2, 3] y is not a copy of x but rather reference to the list attached to x as well
English
0
0
0
50
Teerath
Teerath@TeerathJammar·
@PythonPr B List is mutable data structure here both x and y have reference of list
English
0
0
0
320
GENIE™️
GENIE™️@o_agbajee·
@PythonPr a. because both x and y are not the list itself but just references to the list
English
0
0
0
197
TechLatest.Net
TechLatest.Net@TechlatestNet·
@PythonPr interesting take, feels like we’re watching sci fi turn into reality in real time
English
0
0
0
99
Paylaş