[Tutor] Question about Functions

novo shot novoshot at gmail.com
Tue Sep 10 19:34:50 CEST 2013


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")

result=theFunction("this either")
print "reply is: ", result

---------------------------------------------
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?

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.

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130910/04457fa1/attachment-0001.html>


More information about the Tutor mailing list