If the elements of the list point to same memory address, how are the two list not referring to the same object?

I initialize two lists as follows:

>>> a = [1]
>>> b = [1]

Then I find the memory location of the elements at index 0 for both the lists:

>>> id(a[0])
>>> id(b[0])

The address of both the element is the same. But when I try to find out if both the lists are referring to the same object, I get 'False'

>>> a is b

My question is, if the elements of the list refers to the same memory, why do the list not refer to the same object?

Read more here: https://stackoverflow.com/questions/65701847/if-the-elements-of-the-list-point-to-same-memory-address-how-are-the-two-list-n

Content Attribution

This content was originally published by Ankit Sahay at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: