Here is something odd that I came across while experimenting with the 'is' keyword. When I use Python built-ins to create identical objects, Python assigns the same id to them:
>>> a = str()
>>> b = str()
>>> id(a), id(b)
(29857888 29857888)
>>> a is b
True
Creating the string explicitly works the same way:
>>> a = ''
>>> b = ''
>>> id(a), id(b)
(29857888 29857888)
>>> a is b
True
However, when I make my own classes, Python assigns different ids.
>>> class MyClass:
... pass
>>> c = MyClass()
>>> d = MyClass()
>>> id(c), id(d)
(16566256 16566800)
>>> c is d
False
How/why does Python do this? Is there a way to implement this "id matching" functionality for my own classes?