Can I call a one-parameter Python function without using parentheses?

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.
+5
source share
4 answers

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.

- ( , ), - - s = sum((f(x) for x in items)) ( , ), sum(f(x) for x in items)

+6

iPython - -autocall ( -autocall 0, feature, -autocall 1, , -autocall 2, ).

+4

functions, statements keywords (-).

fooobar.com/questions/63675/... ( ) , Python ( , 99,99% ).

+2

, ... : sum (x 2 x (10)), : (operator.add, (x 2 x (10))).

.

0

All Articles