[Python-ideas] Commas [was Re: except expression]

Steven D'Aprano steve at pearwood.info
Mon Feb 17 22:07:17 CET 2014


On Mon, Feb 17, 2014 at 04:00:28PM +0100, M.-A. Lemburg wrote:

> Commas are indeed too overloaded already.
> 
> Guess what these evaluate to :-)
> 
> x = lambda y: y, 2
> x = 2,
> x = 1, 2,
> x = {1:2,}

With the exception of the first one, where I'm not only 90% confident, I 
don't think there is any difficulty with any of those.

The first makes x a tuple containing (function, 2).

The second is a tuple of one element, (2,).

(Remember that, with the exception of the empty tuple, tuples are 
created by commas, not round brackets.)

The third is a tuple of two elements, (1, 2).

The last is a dict with one key:item pair {1:2}.

The only one I needed to check at the interactive interpreter was the 
one with the lambda.


-- 
Steven


More information about the Python-ideas mailing list