When I declare a variable in Python it references an object. In this case my object is the string 'test'. When I concatenate it with 'ing123', the variable a now points to a string object 'testing123'. However the reference count for 'testing123' does not increase. Why does this happen? I thought that python would simply rereference the previously existing 'testing123' string object. In this case it appears it's creating another object that getrefcount does not recognize. I guess my question is.... why does this occur? I was expecting the second call to getrefcount to return a 5 instead of a 4.
from sys import getrefcount
b = 'testing123'
print getrefcount('testing123')
a = 'test'
a += 'ing123'
print getrefcount('testing123')
print a
prints...
4
4
testing123