Defining functions

Ben Finney bignose-hates-spam at
Thu Nov 20 06:30:23 CET 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:


> 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

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

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


 \        "Computers are useless. They can only give you answers."  -- |
  `\                                                     Pablo Picasso |
_o__)                                                                  |
Ben Finney <>

More information about the Python-list mailing list