Is empty string cached?
Farshid Lashkari
flashkNO at SPAMgmail.com
Wed Feb 15 22:26:08 EST 2006
> It takes far too little evidence to induce belief:
>
> >>> a = "hello"
> >>> b = "h"+"ello"
> >>> a is b
> False
> >>> c = "hello"
> >>> b is a
> False
> >>>
I don't understand the point of your last expression. Were you intending
this instead:
>>> c is a
True
However, the following commands add to my confusion:
>> a = 'wtf?'
>> b = 'wtf?'
>> a is b
False
So how are string literals cached? Is there an explanation somewhere? Is
it some freaky voodoo, and I should just assume that a string literal
will always generate a new object?
Thanks,
Farshid
More information about the Python-list
mailing list