"Data blocks" syntax specification draft

bartc bc at freeuk.com
Tue May 22 13:51:30 EDT 2018


On 22/05/2018 15:25, Chris Angelico wrote:
> On Tue, May 22, 2018 at 8:25 PM, bartc <bc at 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.

No? Take these:
 a = (10,20,30)
 a = [10,20,30]
 a = {10,20,30}
If you print type(a) after each, only one of them is a tuple - the one 
with the round brackets.
The 10,20,30 in those other contexts doesn't create a tuple, nor does it 
here:
 f(10,20,30)
Or here:
 def g(a,b,c):
Or here in Python 2:
 print 10,20,30
and no doubt in a few other cases. It's just that special case I 
highlighted where an unbracketed sequence of expressions yields a tuple.
The comma is just generally used to separate expressions, it's not 
specific to tuples.
-- 
bart


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /