(Apr-09-2023, 08:05 AM)Gribouillis Wrote: function call parentheses suffice
This is such a tricky thing. Am I correct to guess there is no difference in program output between
func((x is e or x == e for e in y))
and func(x is e or x == e for e in y)
?I am pasting the generator expression doc for completion: https://docs.python.org/3/reference/expr...xpressions
Quote:6.2.8. Generator expressions
A generator expression is a compact generator notation in parentheses:
generator_expression ::= "(" expression comp_for ")"
A generator expression yields a new generator object. Its syntax is the same as for comprehensions, except that it is enclosed in parentheses instead of brackets or curly braces.
Variables used in the generator expression are evaluated lazily when the __next__() method is called for the generator object (in the same fashion as normal generators). However, the iterable expression in the leftmost for clause is immediately evaluated, so that an error produced by it will be emitted at the point where the generator expression is defined, rather than at the point where the first value is retrieved. Subsequent for clauses and any filter condition in the leftmost for clause cannot be evaluated in the enclosing scope as they may depend on the values obtained from the leftmost iterable. For example: (x*y for x in range(10) for y in range(x, x+10)).
The parentheses can be omitted on calls with only one argument. See section Calls for details.