what does is ?
Jonas Geiregat
kemu at sdf-eu.org
Thu Nov 28 08:20:27 EST 2002
Gerhard Häring wrote:
> Padraig Brady wrote:
>
> >Gerhard Häring wrote:
> >
> >>Jonas Geiregat wrote:
> >>
> >>
> >>>I saw something
> >>>import string
> >>>string._StringType is str
> >>>what does this specially that IS
> >>
> >>The "is" operator compares object *identity*, rather than equality,
> which
> >>the "==" operator does.
> >
> >Well why does the following happen on 2.2?
> >Is Python being clever about merging variables?
> >
> >s1="123"
> >s2=s1[:]
> >s1 is s2 #true?
>
>
> Yes. Certain strings (not all) are being "interned". And certain ints
> (not all)
> are interned, too:
>
> >>> a = 5
> >>> b = 10/2
> >>> a is b
> 1
> >>> x = 1000000000000
> >>> y = 2000000000000 / 2
> >>> x is y
> 0
>
> But it seems to me that the [:] slicing has an additional
> optimization, apart
> from interning.
why is x is y 0 and a is b 1
I don't get it it's the same code only different and bigger numbers
More information about the Python-list
mailing list