ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
[Tutor] functions in Python
by Steve Nelson other posts by this author
Apr 17 2006 9:42AM messages near this date
Re: [Tutor] Changing lists in place | Re: [Tutor] functions in Python
Sorry - including list.

On 4/17/06, Payal Rathod <payal-python@[...].com>  wrote:
>  what is the difference between,
> 
>  def func():
>          ....
> 
>  and
> 
>  def func(x):
>          ....

When you define a function, you are writing a block of code which you
can ask to perform a task.  The task may be simple, and not require
any additional information, or it may be more complex and need
information.

Take a simple analogy.  Let's suppose I gave you the instruction
"Switch off the light" and there was only  one light, you wouldn't
need any more information.  We could call that:

def toggleLight():

Now let's take a more complicated examle - making tea.  If I give you
the instruction "Make me a cup of tea" you might ask questions like
"Milk? Sugar? Kind of tea?"  I need to give you this information
before you can perform the task.  Similarly in a function - you may
need to pass information (arguments) to the function.  Here's the tea
example:

def makeTea(sugar, milk, kind):

We might call the function as follows:

makeTea(2, "none", "darjeeling")

The internals of the function would be able to parse the arguments you
gave it, and carry out the task you've asked it to do.

As to when to use which, I think you'll find that most of the
functions you write will require information if they're to be of much
use.  Only a very simple function doesn't take any arguments.

Hope that helps :o)

S.
> 
>  When to use which? (please do not say "returns a value" for I do not understand the meanin
g
>  of the same)
> 
>  With warm regards,
>  -Payal
>  _______________________________________________
>  Tutor maillist  -  Tutor@[...].org
>  http://mail.python.org/mailman/listinfo/tutor
> 
_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Steve Nelson
Payal Rathod
Eric Walker
Danny Yoo
Terry Carroll
Alan Gauld
Paul D. Eden
Danny Yoo

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved