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

Partner Sites
JustLinux.com
Linux Planet
PHPBuilder
Technology Jobs

Top White Papers

  • The number, complexity, and diversity of cyber threats are soaring. Businesses are increasingly concerned about the risks they face and 91% of organizations...
    Download

  • This interactive white paper from CIO Magazine and EMC lays out the benefits of big data and predictive analytics, provides tips on how to get started,...
    Download

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: