pass-by-reference and pass-by-value

Arguments in python are passed by value, BUT that value is a reference. If it would be passed by reference, given the following code
>> def func(arg):
... arg = ['another value']
...
>>> value = ['original value']
>>> func(value)

A
>> print value
should display - guess -
['another value'].

It gives ['original value'], though.

So, there is no pass-by-reference in Python. Never.

Try equivalent code in C++ and the reference-operator, then you'll see that pass-by-reference indeed yields ['another value'].

Using some function on the object-argument (which changes the object's state like append does) does not show whether the mechanism used is -by-reference or -by-value.

Reply

The content of this field is kept private and will not be shown publicly.
Type this to prove you are human.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ads (you can disable these if you log in)