Checkpoint 2.10.1.
a = 5
b = a
b = a
bruce
is printed, its value is 5, and the second time, its value is 7. The assignment statement changes the value (the object) that bruce
refers to.a is equal to b
now, then a will always equal to b
. In Python, an assignment statement can make two variables refer to the same object and therefore have the same value. They appear to be equal. However, because of the possibility of reassignment, they don’t have to stay that way:a
but does not change the value of b
, so they are no longer equal. We will have much more to say about equality in a later chapter.<-
or :=
. The intent is that this will help to avoid confusion. Python chose to use the tokens =
for assignment, and ==
for equality. This is a popular choice also found in languages like C, C++, Java, and C#.x = 15
y = x
x = 22