[Python-Dev] Python Language Reference has no mention of list comÃprehensions

Glenn Linderman v+python at g.nevcal.com
Thu Dec 3 21:01:54 EST 2015


On 12/3/2015 5:56 PM, Chris Angelico wrote:
> You come across something syntactic that begins by opening a square
> bracket, and you know that its semantics are: "construct a new list".
> That's what's common here.
>
> What goes*inside*  those brackets can be one of two things:
>
> 1) A (possibly empty) comma-separated sequence of expressions
>
> 2) One or more nested 'for' loops, possibly guarded by 'if's, and a
> single expression
>
> So we have two subforms of the same basic syntax. The first one
> corresponds better to the output format, in the same way that a string
> literal might correspond to its repr under specific circumstances.
> Neither is a literal. Neither is a call to a constructor function
> (contrast "list()" or "list.__new__(list)", which do call a
> constructor). So what is this shared syntax? Whatever word is used,
> it's going to be a bit wrong. I'd be happy with either "constructor"
> or "display", myself.

Construction.  It includes an implicit constructor call and does more.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151203/9ed6e566/attachment.html>


More information about the Python-Dev mailing list