I am new to Python (and dont know much about programming anyway), but I remember reading that python generally does not copy values so any statement a = b makes b point to a. If I run
a = 1
b = a
a = 2
print(b)
gives the result 1. Should that not be 2?
No, the result should be 1.
Think of the assignment operator (
=) as the assignment of a reference.This whole distinction really is most important when dealing with mutable objects such as
lists as opposed to immutable objects likeint,floatandtuple.Now consider the following code: