Why tuple with one item is no tuple

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Tue Mar 22 19:37:21 EST 2005


On 15 Mar 2005 11:25:15 -0500, rumours say that roy at panix.com (Roy
Smith) might have written:

>The big question is, is it the parens that make it a tuple, or is it
>the comma?  If you go along with the parens school of thought, then
>(1,) is the special case.  If you believe in commas, then the () is
>the special case.  In either case, it's a bit ugly, but we learn to
>overlook the occasional cosmetic blemishes of those we love :-)

My take on this is that comma defines tuples, and () is the exception.

.>> tpl = 1, 2, 3 * 4; print tpl
(1, 2, 12)
.>> tpl = (1, 2, 3) * 4; print tpl
(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)

So parentheses just change precedence (comma has lower precedence than
star).
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...



More information about the Python-list mailing list