string identity and comparison

alex23 wuwei23 at gmail.com
Thu Dec 16 19:56:12 EST 2010


On Dec 16, 9:55 pm, Jean-Michel Pichavant <jeanmic... at sequans.com>
wrote:
> I'd like to illutrate the fact that comparing strings using identity is,
> most of the time, a bad idea. However I'm searching a short example of
> code that yields 2 differents object for the same string content.
>
> Anyone has that kind of code ?

It's quite obvious when they come from different contexts:

>>> def f(): return 'some string'
...
>>> def g(): return 'some string'
...
>>> f() == g()
True
>>> f() is g()
False



More information about the Python-list mailing list