call by reference howto????

7stud bbxx789_05ss at yahoo.com
Thu Feb 28 05:09:11 CET 2008


On Feb 27, 5:02 pm, Tamer Higazi <n... at mail.de> wrote:
> Hi!
> Can somebody of you make me a sample how to define a function based on
> "call by reference" ???
>
> I am a python newbie and I am not getting smart how to define functions,
> that should modify the variable I passed by reference.
>
> thanks in advance
>
> Tamer

def my_func(x):
    x[0] = 4


my_list = [3]
print my_list

my_func(my_list)
print my_list

--output:--
[3]
[4]



class MyData(object):
    pass

def another_func(obj):
    obj.val += 10


md = MyData()
md.val = 20
another_func(md)
print md.val

--output:--
30



More information about the Python-list mailing list