why does the % string format operator only take tuples?

Clarence Gardner clarence at netlojix.com
Tue Apr 3 20:37:16 EDT 2001


On Tue, 03 Apr 2001, Ram Bhamidipaty wrote:
>
>
>Does anyone else think it would be a good idea of the % operator
>were extended to also handle lists?
>
>-Ram

You want as few types as possible to be treated as containers for the
data to be formatted, because you have a problem formatting an object
of those types.

For example, if you want to print the tuple (1,2), you can't use
    print '%s' % (1,2)
Instead, you have to do something like
    print '%s' % `(1,2)`
Making % treat lists as tuples would just mean there were more objects
that can't be formatted.



More information about the Python-list mailing list