References

When we assign variables such as theSum = 0, we are assigning references.

This is especially important to note when we are copying lists for example.

myList = [1,2,3,4]
A = [myList]*3
print(A)
myList[2]=45
print(A)

The above produces:

[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
[[1, 2, 45, 4], [1, 2, 45, 4], [1, 2, 45, 4]]

This is because we have essentially copied the reference of myList three times into A. Mutating myList will then also mutate A.

If we have two objects A and B. A == B will only be true if the reference of A is the same as B even though the contents of A may be exactly the same as B. This is known as shallow equality.

Deep equality can be achieved by overriding the __eq__ method in the class (see OOP section below).