1

I've found many articles providing examples like the following:

listA = [0]
listB = listA
listB.append(1)
print listA
print listB

The gaol is to show that both lists are pointing to the same object, then if that object is changed, both lists display that change. In fact:

print listA is listB

displays True...So far so good.

However, I cannot figure out why the following example does not work as the previous one.

listA = [1, 2, 3]
max_val = max(listA)

print max_val is listA[-1]  # True

max_val = 10

print max_val is listA[-1] # False

so the list is not changed even though max_val is pointing to the last element of the list.

Why is that ?

Harry C.
  • 41
  • 1
  • 4

0 Answers0