Is it possible to pass a parameter by reference?

M.E.Farmer mefjr75 at hotmail.com
Sun Feb 27 00:45:37 EST 2005


Anthony Liu wrote:
> I defined two functions, f1 and f2.
>
> f1 modifies the value of a variable called apple.
>
> I want to pass the modified value of apple to f2.
>
> How can I do this?  I got stuck.


Py>def f1(apple):
...    apple += 1
...    f2(apple)

py>def f2(apple):
...    print 'you have %s apples' % apple

py>f1(4)
'you have 5 apples'
Read the docs this is pretty basic, it will save you time.
If in doubt try it out.
Use the interpreter, it is your friend.
hth,
M.E.Farmer




More information about the Python-list mailing list