Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


More on LinuxToday


Book Excerpt: Chapter 6: Functions and Functional Programming

Oct 09, 2009, 23:05 (0 Talkback[s])
(Other stories by David Beazley)

"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

Related Stories: