error in syntax description for comprehensions?

Terry Reedy tjreedy at
Thu Mar 30 20:43:21 EDT 2017

On 3/30/2017 4:57 PM, Boylan, Ross wrote:
> describes the syntax for comprehensions as
> comprehension ::=  expression comp_for
> comp_for      ::=  [ASYNC] "for" target_list "in" or_test [comp_iter]
> comp_iter     ::=  comp_for | comp_if
> comp_if       ::=  "if" expression_nocond [comp_iter]
> Is the comp_for missing an argument after "in"?

The or_test *is* the 'argument'.

> One has to follow the definition of or_test and its components,
 > but I can't find anything that results to a single variable
 > or expression.

An or_test *is* a single expression.  Like all python expressions, it 
evaluates to a python object.  In this case, the object is passed to 
iter() and so the object must be an iterable.

 >>> a, b = None, range(3)
 >>> a or b
range(0, 3)
 >>> for i in a or b: print(i)


Terry Jan Reedy

More information about the Python-list mailing list