Mar-01-2019, 12:58 PM
id(some_list)
always gives you the address of list object in memory,not what the list contain.Since lists are mutable they create new object in memory every time.
>>> id([]) 13622648 >>> id([]) 8717336 >>> id([]) 13621328The object integer inside list container is immutable and can point to same place in memory.
>>> x = [1] >>> y = [1] >>> id(x) == id(y) False >>> # is use id() >>> x is y False >>> # == dos not >>> x == y True >>> # Test integer object inside of list >>> id(x[0]) == id(y[0]) True >>> >>> help(id) Help on built-in function id in module builtins: id(obj, /) Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (CPython uses the object's memory address.)