'11' + '1' is '111'?

Benjamin Kaplan benjamin.kaplan at case.edu
Thu Oct 29 20:52:37 EDT 2009


On Thu, Oct 29, 2009 at 8:43 PM, metal <metal29a at gmail.com> wrote:
> '11' + '1' == '111' is well known.
>
> but it suprises me '11'+'1' IS '111'.
>
> Why? Obviously they are two differnt object.
>
> Is this special feature of imutable object?

It's an implementation detail of small strings without spaces and
small numbers. You're more likely to reuse those values, so Python
caches them. You shouldn't rely on it. It's not guaranteed to stay the
same between different implementations, or even different versions of
CPython.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list