Traditionally, computer science texts show item references as pointers with diagrams that have boxes as variables, objects or places in memory, and arrows between them. Some people find this kind of explanation helpful, and it is definitely worth taking a look (see the Wikipedia Pointer Article as one example). Other people find the diagrams with lots of arrows just add to the confusion.

The example below shows how Python's is operator is equivalent to comparing the id() of two variables. As a point of interest, it's interesting to see how Python treats numbers and strings as well as mutables. The example also illustrates the use of dictionaries instead of lists.


Item References

def Same(x,y):
  return id(x) == id(y)
A = [2,1,9]
D = [2,1,9]
B = {True:A, -20:1.5, "blue":17}
C = A[2]
print C is B[True][2]
print B[True] is A
print Same(B[True],A)
print Same(A,D)
v = "Greetings"
w = "Greetings"
print v is w


For readers who prefer to see lots of arrows and pointers in action, the Python Tutor can be valuable.