Re: [Tutor] functions in Python

2006-04-18 Thread Terry Carroll
On Tue, 18 Apr 2006, Danny Yoo wrote: > Just as a side note: no semicolons needed. *wink* Yesterday, I tested something with a two-line perl program. I could not for the life of me see why I was getting a syntax error. It was only after 15 minutes of looking up red herrings that it finally d

Re: [Tutor] functions in Python

2006-04-18 Thread Danny Yoo
> New at this but the f(x) with the return statement passes the value back > to be used in something. The one with the print statement just prints > it. Correct me if I am wrong experts > def f(x): > x = x + 1; > return x > > def g(x): > x=x + 1; > print x; Hi Eric, Yes, you've got it

Re: [Tutor] functions in Python

2006-04-18 Thread Eric Walker
Payal Rathod wrote: On Mon, Apr 17, 2006 at 05:42:05PM +0100, Steve Nelson wrote: 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 informati

Re: [Tutor] functions in Python

2006-04-18 Thread Payal Rathod
On Mon, Apr 17, 2006 at 10:31:04AM -0700, Danny Yoo wrote: > One view that's common is the idea that a function is a box that takes > an input and returns an output: Thanks a lot for the detailed help. Well, I have now got atleast basics of functions, will be doing some more reading on it in nex

Re: [Tutor] functions in Python

2006-04-17 Thread Alan Gauld
Wow! I checked the list at lunchtime and there were only a few things here, then I check again now and lots of stuff from my tutor! Fortunately most of it has been answered already - thanks folks - but I feel honour bound to contribute something... > What is the difference between, > def

Re: [Tutor] functions in Python

2006-04-17 Thread Paul D. Eden
This only happens because the python interactive command-line (what you get when you just type 'python' in a terminal window) prints return values automatically for you. If you were executing f(4) in a program/script, the return value would be lost. Paul Payal Rathod wrote: > On Mon, Apr 17,

Re: [Tutor] functions in Python

2006-04-17 Thread Danny Yoo
On Mon, 17 Apr 2006, Payal Rathod wrote: > What is the difference between, > def f(x): > ... return x > ... f(4) > 4 > def f(x): > ... print x > ... f(4) > 4 > > Both give same results. Clarification. Both "show" the same results from the interpreter. From what yo

Re: [Tutor] functions in Python

2006-04-17 Thread Danny Yoo
> Sorry, but you have confused me more ;) Can you give an simple example > of just function() ? Where can it be useful? > > And when you say it returns a value, what do you mean by that? return to > whom and what exactly? One view that's common is the idea that a function is a box that takes an

Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:42:05PM +0100, Steve Nelson wrote: > 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. What is the di

Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:10:51PM +0100, Robert Schumann wrote: > You could say "I kick" (which is like func(), because you're not > specifying an object to operate on) or your could say "I kick the > ball" (in which case x = "the ball"). > Sorry, but you have confused me more ;) Can you give

Re: [Tutor] functions in Python

2006-04-17 Thread Robert Schumann
Payal Rathod wrote: > Hi, > I am now reading Alan's tut on Python, before that I have read a few other > tuts too. > But I am not getting functions exactly. I mean what is the difference between, > > def func(): > > > and > > def func(x): > > > When to use which? (please

Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:02:07PM +0100, Adam wrote: > The x is a name for a value that you pass in to the function. To call > the first function you would do > >>> func() > > and the second function: > >>> func(5) # 5 is just an example it could be any value depending on > the function. Sorry b

[Tutor] functions in Python

2006-04-17 Thread Steve Nelson
Sorry - including list. On 4/17/06, Payal Rathod <[EMAIL PROTECTED]> 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 si

Re: [Tutor] functions in Python

2006-04-17 Thread Adam
On 17/04/06, Payal Rathod <[EMAIL PROTECTED]> wrote: > Hi, > I am now reading Alan's tut on Python, before that I have read a few other > tuts too. > But I am not getting functions exactly. I mean what is the difference between, > > def func(): > > > and > > def func(x): > ...

[Tutor] functions in Python

2006-04-17 Thread Payal Rathod
Hi, I am now reading Alan's tut on Python, before that I have read a few other tuts too. But I am not getting functions exactly. I mean what is the difference between, def func(): and def func(x): When to use which? (please do not say "returns a value" for I do not un