Checkpoint 2.12.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 (and other programming languages), 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.a = 5
the literal number 5 evaluates to 5, and is given the name a
. In the second statement, the variable a
evaluates to 5 and so 5 now ends up with a second name b
.<-
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