Why are tuples immutable?

Fredrik Lundh fredrik at pythonware.com
Tue Dec 14 08:16:24 EST 2004


Gerrit <gerrit at nl.linux.org> wrote:

> Apart from historical, compatibility reasons, why is
>
>    "foo %s bar %s" % [2, 4]
>
> illegal?
>
> I could imagine that anything accepting numerical values for __getitem__
> (foo[0], foo[1], ...) or that is iterable (foo.next(), foo.next()) could
> be sensibly used as a formatting rhs. Of course, it is not compatible
> because "foo %s" % [2, 4] is correct and "foo %s" % (2, 4) is not, but
> are there other reasons that it has been chosen like this?

so what should

    "foo %s bar %s" % "24"

do?

</F> 






More information about the Python-list mailing list