[Tutor] iterators

eryk sun eryksun at gmail.com
Mon Jul 4 21:12:42 EDT 2016

On Mon, Jul 4, 2016 at 9:56 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
> So the extra trailing comma in a 1-tuple parenthesized expression is
> just there to make it different looking, to disambiguate it from the
> use of parentheses for expression grouping.

The comma is the distinguishing element of non-empty tuple literals.
It's always required in order to create a non-empty tuple, with or
without brackets. For example:

    >>> 27,

The parentheses are optional for a non-empty tuple, but they're often
required because a comma has low precedence. For example, with the
expression `x in y, z`, Python first evaluates `x in y`. If the goal
is to check whether x is in the the tuple `y, z`, then it has to be
written `x in (y, z)`.

More information about the Tutor mailing list