December 2018
Beginner to intermediate
796 pages
19h 54m
English
When we discussed objects at the beginning of this chapter, we saw that when we assigned a name to an object, Python creates the object, sets its value, and then points the name to it. We can assign different names to the same value and we expect different objects to be created, like this:
>>> a = 1000000 >>> b = 1000000 >>> id(a) == id(b) False
In the preceding example, a and b are assigned to two int objects, which have the same value but they are not the same object, as you can see, their id is not the same. So let's do it again:
>>> a = 5 >>> b = 5 >>> id(a) == id(b) True
Oh, oh! Is Python broken? Why are the two objects the same now? We didn't do a = b = 5, we set them up separately. Well, the answer is performances. ...
Read now
Unlock full access