<snip> > A tuple is defined by commas, depending on context. However, > parentheses are typically required because commas have low precedence. > > >>> 1, 2 + 3, 4 > (1, 5, 4) > > >>> (1, 2) + (3, 4) > (1, 2, 3, 4) > > An empty tuple is a special case: > > >>> x = () > >>> type(x) > <type 'tuple'>
Why do I need to use a trailing comma to create a singleton tuple? Without a comma it seems to mean "parenthesized single object", ie the parentheses are basically not there. >>> type((0,)) <type 'tuple'> >>> type((0)) <type 'int'> >>> (0) 0 >>> x = (,) SyntaxError: invalid syntax >>> (0,0) (0, 0) _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor