The Python documentation specifies that is is legal to omit the parentheses if a function only takes a single parameter, but
myfunction "Hello!"
generates a syntax error. So, what’s the deal?
EDIT:
The statement that I read only applies to generator expressions:
The parentheses can be omitted on calls with only one argument.
For your edit:
If you write down a generator expression, like
stuff = (f(x) for x in items)you need the brackets, just like you need the[ .. ]around a list comprehension.But when you pass something from a generator expression to a function (which is a pretty common pattern, because that’s pretty much the big idea behind generators) then you don’t need two sets of brackets – instead of something like
s = sum((f(x) for x in items))(outer brackets to indicate a function call, inner for the generator expression) you can just writesum(f(x) for x in items)