Python question help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python question help me

Fitst sorry for my poor english skill Read this code: def func(x): x[0]=['def'] x[1]=['abc'] return id(x) q=['abc','def'] print(id(q)==func(q)) This code results in 'true' according to the question, but I can't get it why :( I think answer is false because order of component is changed through func() Isn't func(q) same as id(['def','abc']) ?? Why not?

1st Apr 2020, 5:28 PM
Neru
Neru - avatar
2 Answers
+ 1
It doesn't change because id() return the address where the object is stored in the memory.
1st Apr 2020, 5:42 PM
Simone Crema 🇮🇹
Simone Crema 🇮🇹 - avatar
0
If you have a bit of time and want to understand more deeply, you might take a look into this tutorial I made a while ago: https://code.sololearn.com/c89ejW97QsTN/?ref=app
1st Apr 2020, 10:03 PM
HonFu
HonFu - avatar