Puzzled by "is"

kyosohma at gmail.com kyosohma at gmail.com
Thu Aug 9 22:24:48 CEST 2007


On Aug 9, 2:53 pm, Steve Holden <st... at holdenweb.com> wrote:
> Dick Moores wrote:
> > At 10:46 AM 8/9/2007, Bill Scherer wrote:
> >> Dick Moores wrote:
> [...]
> >> There is only one empty tuple.
> >> Does that clear it up for you?
>
> > But isn't that the same as saying, "That's just the reality of
> > Python; it is what it is."? I want to know why there is only one
> > empty tuple, but more than one (1,).
>
> Why? Because.
>
> Seriously, it's just an optimization by the implementers. There is no
> need for more than one empty tuple, since tuples can never be modified
> once created.
>
> But they decided not to create (1, ) in advance. They probably knew that
> hardly anybody would want to create that tuple ;-) [Seriously: if you
> started trying to predict which tuples would be used you would go
> insane, but the empty tuple is the most likely candidate].
>
> > Also,
> >  >>> [] is []
> > False
>
> In that case it would definitely NOT make sense to have them the same
> list. Python always ensures that the [] constructor creates a new list,
> since that list may be bound to one or more variables and mutated. You
> wouldn't want
>
>    a = []
>    b = []
>    a.append("boo!")
>
> to change b so it was no longer an empty list. If you wanted a and b to
> reference the same list you would change the second statement to
>
>    b = a
>
> regards
>   Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd          http://www.holdenweb.com
> Skype: holdenweb      http://del.icio.us/steve.holden
> --------------- Asciimercial ------------------
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> ----------- Thank You for Reading -------------

Steve,

I thought you'd probably weigh in on this esoteric matter. Very
illuminating, as usual.

Mike




More information about the Python-list mailing list