Post

Rahul Rode
Rahul Rode@RodeRahul56771·
@PythonPr Output is : [1,2,3] Because Y=X.copy() is created the copy of X and store in Variable Y X.append(4) is added 4 at last index of X but not in Y We print(Y) that's why Output is [1,2,3]
English
0
0
6
1.1K
Jimmy Fikes
Jimmy Fikes@akajim·
@PythonPr The copy() method for y becomes a shallow copy that is bound to the original list object (i.e., [1,2,3]). When 4 is appended to x, y is still bound to [1,2,3]. So print(y) gives [1,2,3]
English
0
0
5
2.7K
Ankit Aggarwal
Ankit Aggarwal@TechAheadAnkit·
@PythonPr My bad. I misread it as copy library. list.copy returns completely new list Hence any change in x will not reflect in y Y will be [1,2,3] we can use id(x) and id(y) to validate there addresses both will be different
English
1
0
4
3.2K
American Express
American Express@AmericanExpress·
As the new Official Payments Partner of the NFL, Amex is bringing Card Members closer to the action with special access and experiences at select events worldwide.
English
0
5
84
885.7K
Jeff
Jeff@Jeff72571425107·
@PythonPr since when you used x.copy() copy constructor function to assign to y, y is a new object and is not pointing x as it would have if you merely assigned x to y. print(y) will print [1,2,3] print(x) will print [1,2,3,4] ans: [1,2,3]
English
0
1
2
684
Vandana
Vandana@vandanasoc28779·
@PythonPr Y will be [1,2,3] as x.copy returns new list.
English
0
0
0
1K
PourDay
PourDay@pourdayconcrete·
Weather apps weren't built for concrete. PourDay calculates your ACI 305R evaporation rate in real time — so you know before the truck leaves the yard. Free for contractors. No subscription.
English
0
0
0
1.3K
Madhav ⚡️
Madhav ⚡️@askmaddyy·
@PythonPr The output should be [1,2,3], Y should remain untouched as list.copy() creates a shallow copy and here y points to a completely different list address so Y remains unchanged.
English
0
0
4
977
akhilesh kumar ojha
akhilesh kumar ojha@kumarakh·
@PythonPr [1, 2, 3] You made a copy, not a reference. So changes to x don’t affect y. Since copy() creates a new list, modifying x doesn’t affect y, so the output remains [1, 2, 3]
English
0
0
2
780
mahiro
mahiro@k_mahiro813·
@PythonPr 出力結果は[1,2,3] Xに配列として[1,2,3]を格納、 その後yにその時点でのxの内容をコピーした。 そのさらに後でxに4を追加。 ここでxは[1,2,3,4]になるが、 print(y)ではyに値が反映された時点の[1,2,3]が出力される。
日本語
0
0
0
99
Grok
Grok@grok·
Ready to bring ideas to life? Try Grok Imagine today
English
0
1.2K
9.7K
25.2M
Paylaş