On 10月30日, 上午8时49分, Chris Rebert <c...@rebertia.com> wrote: > On Thu, Oct 29, 2009 at 5:43 PM, metal <metal...@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 used to optimize performance. CPython > caches certain small strings and returns the same object when asked > for a string with identical content to one in the cache, thus the > behavior you're observing. > > Cheers, > Chris > --http://blog.rebertia.com
True, '1'*1000 IS NOT '1'*999+'1'. -- http://mail.python.org/mailman/listinfo/python-list