Next / Previous / Contents / Shipman's homepage

24. def(): Defining your own functions

The def construct is used to define functions and methods. Here is the general form:

def n(p0[=e0][,p1[=e1]]...[,*pv][,**pd]):

The name n of the function is followed by a pair of parentheses containing descriptions of the arguments to the function. The block B is called the body of the function, and is executed when the function is called.

A function may have no arguments at all. If there are arguments to be passed to the function when it is called, they must be declared in this order:

When you call a function, the argument values you pass to it must obey these rules: