On Tue, May 22, 2018 at 9:22 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Tue, May 22, 2018 at 8:25 AM, Chris Angelico <ros...@gmail.com> wrote: >> On Tue, May 22, 2018 at 8:25 PM, bartc <b...@freeuk.com> wrote: >>> Note that Python tuples don't always need a start symbol: >>> >>> a = 10,20,30 >>> >>> assigns a tuple to a. >> >> The tuple has nothing to do with the parentheses, except for the >> special case of the empty tuple. It's the comma. > > Although, if the rule were really as simple as "commas make tuples", > then this would be a list containing a tuple: [1, 2, 3]. > > Curiously, parentheses are also sometimes required for iterable > unpacking. For example:
[SNIP] > py> def foo(): > ... yield 1, 2 > ... > py> list(foo()) > [(1, 2)] > py> def foo(): > ... yield 1, 2, *range(3, 5) > File "<stdin>", line 2 > yield 1, 2, *range(3, 5) > ^ > SyntaxError: invalid syntax Here's another case where parentheses are always required: py> def foo(): ... yield from 1, 2 File "<stdin>", line 2 yield from 1, 2 ^ SyntaxError: invalid syntax This one might be explained by noting that "yield from" is actually an expression and so it could be confusing as to whether this should be equivalent to "yield from (1, 2)" or "(yield from 1), 2". But "yield" has the same issue and does allow an unparenthesized tuple. -- https://mail.python.org/mailman/listinfo/python-list