Why are tuples immutable?

Gerrit gerrit at nl.linux.org
Tue Dec 14 07:32:40 EST 2004


Another tuple/list question.

Fredrik Lundh wrote:
> http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types

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? Or is it
possible that this behaviour will change in Python 3000?

let's-do-Duck-Typing!-ly - y'rs - Gerrit

-- 
Weather in Lulea / Kallax, Sweden 14/12 12:50:
	2.0°C mist mostly cloudy wind 8.9 m/s S (34 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
    -Dwight David Eisenhower, January 17, 1961



More information about the Python-list mailing list