Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9
BroFar ~ swim ~ sir this guy yash he doing spam in solo discussion box . Take any action please.
11th Jul 2020, 6:09 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
yash please remove all your spam comments and only answer with relevant comments to the current question. Thanks and happy coding. https://www.sololearn.com/discuss/1316935/?ref=app https://code.sololearn.com/Wv5gTHy1N6Ji/?ref=app
11th Jul 2020, 6:12 PM
BroFar
BroFar - avatar
+ 3
Since both types are lists, it will give the answer as true
11th Jul 2020, 7:42 AM
Partha Jagdale
Partha Jagdale - avatar
+ 2
you are passing the same list to foo function and just changing its values to list values and returning the id of that list (basically the id of list q) instead of creating a new list and returning it As an example def foo(x): x[0]=["eggs"] x[1]=["spam"] return id(list(x)) q=["spam","eggs"] print(id(q)==foo(q)) this will return false
11th Jul 2020, 11:04 AM
Abhay
Abhay - avatar
+ 2
it is giving true as both id(q) and foo(q) are same lists
13th Jul 2020, 6:57 AM
AMIT KUMAR
AMIT KUMAR - avatar
+ 1
the function gets the id of x. q AND x are both lists so when you compare types it equals True.
11th Jul 2020, 7:23 AM
Slick
Slick - avatar
11th Jul 2020, 7:28 AM
Slick
Slick - avatar
+ 1
The code mutated the list, so the identity is same. The id() function returns identity (unique integer) of an object. And all objects in Python can be either mutable or immutable. In simple words, mutable means 'able to be changed’ and immutable means ‘constant’. Try following example: https://code.sololearn.com/cO74rFh6RIci/#py The identity of Lists are still the same after modified, but the Numbers are different. P.S. Mutable objects: list, dict, set Immutable objects: int, float, complex, string, tuple
11th Jul 2020, 11:58 AM
Esch
Esch - avatar