3 ms·
Using the id to prove it's reusing the same instance is a poor proxy, eg: >>> id([1,2,3]) == id([4,5,6]) True >>> id([1,2,3]), id([4,5,6]) (140
by ndr 5y ago
Using the id to prove it's reusing the same instance is a poor proxy, eg:
>>> id([1,2,3]) == id([4,5,6])
True
>>> id([1,2,3]), id([4,5,6])
(140720308985224, 140720308985224)
It's clearly not the same instance, even though it's at the same address.
Not in this case though, but I'm not sure why the author uses a black-box model to explain it rather than looking at the source, `iadd` uses `extend`: https://github.com/python/cpython/blob/main/Objects/listobject.c#L988 https://github.com/python/cpython/blob/main/Objects/listobje...
- qayxc 5y agoNot to be rude or anything, but if the target audience needs basic semantics explained to them, I don't know they would benefit from an in-depth explanation.
- alisonkisk 5y agoBut if if the author needs basic semantics explained to them, I don't know that the audience would benefit from reading it. And why wouldn't an explanation help the audience learn?
- algorias 5y agoYou need to keep the objects alive obviously, then it works exactly as expected. >>> a = [1,2,3] >>> b = [4,5,6] >>> id(a), id(b) (140659402612872, 140659403098568)