---

Book Excerpt: Chapter 6: Functions and Functional Programming

“Functions are defined with the def statement:

def add(x,y):
    return x + y

“The body of a function is simply a sequence of statements that
execute when the function is called. You invoke a function by
writing the function name followed by a tuple of function
arguments, such as a = add(3,4). The order and number of arguments
must match those given in the function definition. If a mismatch
exists, a TypeError exception is raised.

“You can attach default arguments to function parameters by
assigning values in the function definition. For example:

def split(line,delimiter=','):
    statements


Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis