+ 1
I faced this question in a challenge and don't understand this 'id' thing.Could anyone explain it?
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.
0
Thanks...Lothar



