why does the % string format operator only take tuples?

Alex Martelli aleaxit at yahoo.com
Wed Apr 4 03:53:10 EDT 2001


"Kragen Sitaker" <kragen at dnaco.net> wrote in message
news:UUty6.25420$BC6.6993739 at e3500-chi1.usenetserver.com...
> In article <gha66glj2n4.fsf at synopsys.com>,
> Ram Bhamidipaty  <ramb at synopsys.com> wrote:
> >Does anyone else think it would be a good idea of the % operator
> >were extended to also handle lists?
>
> No.  Lists have the connotation that they could have any number of
> elements and that there isn't much distinction between the elements
> (some come earlier, some later, but they're all the same kind of thing
> in some sense --- any code you could pass foo[0] to should also be able
> to handle foo[1] if it's there).  Tuples have the connotation that
> their elements have distinct meanings.

This is (e.g.) the Haskell interpretation of lists vs tuples -- lists
are homogeneous, tuples need not be -- but, IMHO, it's something of a
stretch to carry it over to Python, where the two kinds of sequences
(and others yet) are interchangeable in so many contexts.  I am quite
happy to have lists silently mutate into tuples, and viceversa, in
many contexts (e.g., I can call f(*range(1,4)), etc, etc); the contexts
where this mutation doesn't happen stand out somewhat unpleasantly...


Alex






More information about the Python-list mailing list