doing:
>>>'a'*20 is "aaaaaaaaaaaaaaaaaaaa"
gives
>>>True
while doing:
>>>'a'*21 is "aaaaaaaaaaaaaaaaaaaaa"
gives
>>>False
Whats going on here? Is this a bug?
doing:
>>>'a'*20 is "aaaaaaaaaaaaaaaaaaaa"
gives
>>>True
while doing:
>>>'a'*21 is "aaaaaaaaaaaaaaaaaaaaa"
gives
>>>False
Whats going on here? Is this a bug?
For smaller objects python is reusing the allocated memory. But for larger objects the reference is changing. Do check this
x='aaaaaaaaaaaaaaaaaaaaa'
y='a'*21
t= 'a'*20
u = 'aaaaaaaaaaaaaaaaaaaa'
Here t and u reference the same string but x and y do not so the object comparison isn't working.