Is it possible to pass a parameter by reference?

Paddy paddy3118 at netscape.net
Sun Feb 27 03:03:05 EST 2005


It is usually clearer to explicitely return values that are changed by
a function and re-assign it to the same variable,

x=something1
a = something2
def f1(s,t):
  # do something with t,
  # do something to s
  return s
a = f1(a,x)

Be aware however that you can wrap 'a' in a list for the same effect,
(but it is not as easy to read).

x=something1
aa = [something2]
def f2(ss,t):
  s= ss[0]
  # do something with t,
  # do something to s
  ss[0]=s
f2(aa,x)
a=aa[0]

-- Pad.




More information about the Python-list mailing list