June 2017
Beginner
352 pages
8h 39m
English
Even operations which seem naturally mutating in nature are not necessarily so. Consider the augmented assignment operator:
>>> t = 5>>> id(t)4297261280>>> t += 2>>> id(t)4297261344
At first glance, it appears that we're asking Python to increment the integer value t by two. But the id() results here clearly show that t refers to two different objects before and after the augmented assignment.
Rather than modifying integer objects, here's a depiction of what's actually happening. Initially, we have the name t referring to an int(5) object:

Next, to perform the augmented assignment ...
Read now
Unlock full access