The Python documentation indicates that it is legal to omit parentheses if a function accepts only one parameter, but
myfunction "Hello!"
generates a syntax error. So what is the deal?
(I am using Python 3.1)
EDIT:
The statement I read applies only to expressions :
The parentheses can be omitted on calls with only one argument.
For your editing:
If you write a generator expression, for example stuff = (f(x) for x in items), you need parentheses, just as you need [ .. ]around list comprehension.
stuff = (f(x) for x in items)
[ .. ]
- ( , ), - - s = sum((f(x) for x in items)) ( , ), sum(f(x) for x in items)
s = sum((f(x) for x in items))
sum(f(x) for x in items)
iPython - -autocall ( -autocall 0, feature, -autocall 1, , -autocall 2, ).
-autocall 0
-autocall 1
-autocall 2
functions, statements keywords (-).
functions
statements
keywords
fooobar.com/questions/63675/... ( ) , Python ( , 99,99% ).
, ... : sum (x 2 x (10)), : (operator.add, (x 2 x (10))).
.