[Tutor] Question about Functions
Joel Goldstick
joel.goldstick at gmail.com
Tue Sep 10 22:24:16 CEST 2013
On Tue, Sep 10, 2013 at 1:49 PM, novo shot <novoshot at gmail.com> wrote:
> Dear tutors:
>
> The following is an example I found in the Raspberry Pi for Dummies book:
>
> #function test
>
> def theFunction(message):
> print "I don't get ", message
> return "ARRRGH!"
>
> theFunction("this")
>
the above line invokes theFunction, and prints "I don't get this". It
returns "ARRRGH" but you con't assign that to a name, so it is lost.
>
> result=theFunction("this either")
>
Now you call theFunction again and it prints "I don't get this either".
You save the ARRRGH bit in result
> print "reply is: ", result
>
You print the value of result with is ARRRGH
>
> ---------------------------------------------
> The result of this code looks like this:
>
> I don't get this
> I don't get this either
> reply is: ARRRGH!
>
> ----------------------------------------------
> Here's what I don't understand:
>
> When I declare a variable to be equal as the fucntion
> (result=theFunction("this either")) is Python also executing the
> function?
>
Yes it is
>
> The way I see it, I only called for the function once before printing
> ARRRGH!! Then after that I declared a variable and then I print.
>
> You see it wrong. Each time you have theFunction(...) in your code that
function is run
> This is how I expected the result to look like:
>
> I don't get this
> reply is: I don't get this either
> ARRRGH!
>
> -----------------------------------------
>
> Can you help me understand? I can't move forward until I understand
> how Python solves this code.
>
> Thanks in advance
> Optional
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130910/450e1f3b/attachment.html>
More information about the Tutor
mailing list