[pypy-dev] comparing strings using is does not works

Michael sparks.m at gmail.com
Wed Jun 5 14:54:51 CEST 2013


On 5 June 2013 13:47, Andrews Medina <andrewsmedina at gmail.com> wrote:

> Hi,
>
> In the code below:
>
> >>>> x = "a"
> >>>> b = "a"
> >>>> x is b
> False
>

It's more consistent than cpython - where the result of "x is b" is
dependent on the length of the string :

Python 2.7.3 (default, Apr 10 2013, 05:46:21)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x="a"*20
>>> b="a"*20
>>> x is b
True
>>> x="a"*21
>>> b="a"*21
>>> x is b
False

Relying on "is" for comparing strings is generally a bug in your code
waiting to be triggered.


Michael.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20130605/61c176c6/attachment.html>


More information about the pypy-dev mailing list