Defining functions

Ben Finney bignose-hates-spam at and-benfinney-does-too.id.au
Thu Nov 20 00:30:23 EST 2003


On 20 Nov 2003 05:21:09 GMT, Jimith87 wrote:
> I'm a newby to python, and have been learning it for a little while

Welcome!  Some time soon you should work through the Python tutorial:

    <http://www.python.org/doc/current/tut/>

> I can't grasp the concept of functions..... If someone could explain
> that in lamers tearms that would be appreciated.

A function is an object that contains code to be executed.  It allows
you to parcel up a conceptual lump of code that does one distinct thing
(say, read a number from an input stream, or calculate a value from two
inputs) and then invoke that bundle of code at other places in your
code.

A function can return a value, so you can assign that value to another
object or use it as input to another function.  A function can be
parameterised; that is, you can pass the function one or more input
parameters that will affect its behaviour.  

Functions allow you to avoid repeating code that is largely similar
throughout your code; it also allows you to abstract a block of code to
a single conceptual operation, making the code that uses it easier to
read.


It sounds like you would benefit from the tutorial "How To Think ike A
Computer Scientist: Learning With Python".  It's here:

    <http://www.ibiblio.org/obp/thinkCSpy/>

-- 
 \        "Computers are useless. They can only give you answers."  -- |
  `\                                                     Pablo Picasso |
_o__)                                                                  |
Ben Finney <http://bignose.squidly.org/>




More information about the Python-list mailing list