Question on Python Function

Peter Otten __peter__ at web.de
Tue May 25 03:18:15 EDT 2010


Kushal Kumaran wrote:

> On Tue, May 25, 2010 at 3:38 AM, joy99 <subhakolkata1234 at gmail.com> wrote:
>> <snip>
>>
>> Dear Vlastimir,
>>
>> As pointed out by Alister, I can print the values of function1 and
>> function2 with the help of another function3, but my target is to call
>> the "add" value of function1 and "mult" value of function2 in a third
>> function or the values and parameters of the third function in fourth
>> function. While calling, I am looking not only to print, but to use
>> them or manipulate them.
>>
>> I hope I am bit clear now.
>>
> 
> If you need to use the values in another function, you need a way to
> let that function get its hands on the values.  Your function1 and
> function2 should return the values they compute instead of printing
> them out.

For example:

 >>> def add(x, y):
...     return x + y
...
>>> def mul(x, y):
...     return x * y
...
>>> def sum_of_squares(x, y):
...     return add(mul(x, x), mul(y, y))
...
>>> sum_of_squares(3, 4)
25

OP: If that addresses your question I suggest that you work through some 
introductory text about python. The python wiki has a few suggestions, see

http://wiki.python.org/moin/BeginnersGuide

Peter



More information about the Python-list mailing list