+ 1

I faced this question in a challenge and don't understand this 'id' thing.Could anyone explain it?

https://code.sololearn.com/cmAC2RJB22si/?ref=app

11th Jun 2019, 5:38 AM
Dipra Irham
Dipra Irham - avatar
2 Answers
+ 2
In python each object has a unique object id. This is a number that you can get with the function id(). In some cases objects like variables can have different names but both show the same id. So in the code sample the variables idA and idB do have the same id, as var B is created as a copy from A. You can check this by adding 2 lines of code as shown here: A = 1 B = A idA = id(A) idB = id(B) print(idA) print(idB) A = 2 idA2 = id(A) print(idA == idB) print(idA == idA2) If you want to get more information about copying variables, search for shallow copy and deep copy.
11th Jun 2019, 8:35 AM
Lothar
Lothar - avatar
0
Thanks...Lothar
11th Jun 2019, 2:40 PM
Dipra Irham
Dipra Irham - avatar