Name
Expressions
Synopsis
expression
function([value
,name
=value
, ...]) object.method([value
,name
=value
, ...])
Any expression can appear as a statement (but statements cannot appear as expressions). Expressions are commonly used for running functions and for interactive-mode printing.
In function and method calls, actual arguments are separated by
commas and are normally matched to arguments in function
def
headers by position. Calls may optionally list
specific argument names in functions to receive passed values, by
using the
name
=
value
keyword syntax.
apply( )-like call syntax
As of Python 2.0, special syntax can be used in function and method
call argument lists to achieve the same effect as an apply( )
built-in function call. If
args
and kw
are
a tuple and a dictionary, respectively, the following are equivalent:
apply(f,args
,kw
) f(*args
, **kw
)
Both formats call function f
with positional
arguments args
and keyword arguments
kw
. The latter format is intended to be
symmetric with function header arbitrary-argument syntax such as
def
f(*
args
,
**
kw
):
.
Get Python Pocket Reference, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.