Slide 5
Slide 5 text
A quick aside about Identity in python
● Python separates out the ideas of ‘is the same as’ (= =) and
‘is the same actual thing as’ (is)
○ Mostly we come across this as being told that we should use ‘is None’ instead of ‘== None’
because something something custom comparison operators
● You can get the identity of an object with the id() function
● Interestingly, python stores a single copy of the integers from -5 to 256, but
creates a new object for integers outside that range each time, so
>>> a = 256
>>> b = 256
>>> a is b
True
>>> a = 257
>>> b = 257
>>> a is b
False