Next: Unary arithmetic operations Up: Primaries Previous: Slicings

Calls

A call calls a callable object (e.g. a function) with a possibly empty series of arguments:


call:           primary "(" [condition_list] ")"

The primary must evaluate to a callable object (user-defined functions, built-in functions, methods of built-in objects, class objects, and methods of class instances are callable). If it is a class, the argument list must be empty; otherwise, the arguments are evaluated.

A call always returns some value, possibly None, unless it raises an exception. How this value is computed depends on the type of the callable object. If it is:

a user-defined function:
the code block for the function is executed, passing it the argument list. The first thing the code block will do is bind the formal parameters to the arguments; this is described in section . When the code block executes a return statement, this specifies the return value of the function call.

a built-in function or method:
the result is up to the interpreter; see the library reference manual for the descriptions of built-in functions and methods.

a class object:
a new instance of that class is returned.

a class instance method:
the corresponding user-defined function is called, with an argument list that is one longer than the argument list of the call: the instance becomes the first argument.


guido@cwi.nl