[Tutor] Question about Functions

Chris Down chris at chrisdown.name
Tue Sep 10 22:25:41 CEST 2013


On 2013-09-10 13:34, novo shot wrote:
> When I declare a variable to be equal as the fucntion
> (result=theFunction("this either")) is Python also executing the function?

You're not declaring it as equal, that would be `==' (or `is' for identity).
`=' assigns, it doesn't check for equality.

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

Why do you expect "reply is" to happen on the second line? It clearly only
happens when printing the returned value, not when printing from inside the
function itself:

> def theFunction(message):
>     print "I don't get ", message
>     return "ARRRGH!"
>
> theFunction("this")
>
> result=theFunction("this either")
> print "reply is: ", result

The extra spaces are because "," implies one. If you don't want a double space
before the message, remove the trailing space in the string.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130910/b8bac7e9/attachment.sig>


More information about the Tutor mailing list