Hi all, I am a newb, got a simple question, anyone can give any idea about it will be great,thanks in advance.

a=2
b=3
def functionA(a,b):
c=a+b
return c
def functionB(c)
return c

but this code doesnt work....what I want is just assign functionA as one of the argument of functionB...how can I do that?

btw,whats the different between print and return?thanks

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by jlm699

hi
here's an example on how to use return using your code:

``````def functionA( n, m ):
# here m and n have nothing to do with a and b
# when this function is called like functionA( a, b ) n gets assigned to the value of a and m gets assigned to the value of b
r = m + n
return r

def functionB( r ):
# same here: function( c ) - r gets assigned to the value of c
answer = r + 1

>>>a = 2
>>>b = 3
>>>c = functionA( a, b )
>>>print c
5
>>>d = functionB( c )
>>>print d
6
>>>``````

Only functions can return values and that value gets assigned to a variable, i.e.
c = functionA( a, b ) means compute a + b in the function and return the result in the variable c. Sorry if this doesn't make much sense :)
If the function used print instead of return, here's what you would get:

``````def functionA( a, b ):
r = a + b
print r

>>>c = functionA( 2, 3 ):
>>>c
5
None``````

Hope I gave you some idea what's going on :)

P.S. next time pls use code tags :)

Edited by masterofpuppets: Forgot code tags

Hi,thanks for your replay,and it does make perfect sence,however,what I want is how can I just call functionB and it automatically gives me answer,the value of a,b are in the code initially.thanks

In the future, please use code tags when posting code. It will allow the forum members here to read your post easily and will give you answers quicker (and of better quality).

Now I will repost your code with code tags so you can see the difference:

``````a=2
b=3
def functionA(a,b):
c=a+b
return c
def functionB(c)