[Tutor] is gotchas?

Pujo Aji ajikoe at gmail.com
Tue Nov 7 01:28:26 CET 2006


For small string object python has optimization method so it is really the
same object!

Cheers,
pujo

On 11/7/06, Tim Johnson <tim at johnsons-web.com> wrote:
>
> * Kent Johnson <kent37 at tds.net> [061106 10:31]:
> >
> > In [9]: a=[1,2]
> >
> > In [10]: b=[1,2]
>
>   Hmmm! Hmmm!
>   Lookee here:
>   ## console session
> >>> a=[1,2]
> >>> b=[1,2]
> >>> a is b
> False
> >>> c='1'  ## one byte
> >>> d='1'  ## one byte
> >>> c is d
> True
> >>> c='1,2'
> >>> d='1,2'
> >>> c is d
> False
>
> The Hmmm! is emmitted because I'm thinking that if everything is an
> object in python, then why does `c is d` evaluate to True when
> the assigned value is 1 byte and evaluate to False when the assigned
> value is more that 1 byte?
>
> I think I ran into this before and that's why I never used `is'.
>
> Good thread. Beats flame wars.
> thanks
> tim
>
> --
> Tim Johnson <tim at johnsons-web.com>
>       http://www.alaska-internet-solutions.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061107/73ac0ce0/attachment.html 


More information about the Tutor mailing list