Hello,
My background is C++
I would like to know for sure if it is possible to pass a value by
reference to a function AND having it changed by the function itself
def changeValue( text ):
text = 'c'
print text
return
[color=blue][color=green][color=darkred]
>>> txt = 'a'
>>>changeValu e( txt )[/color][/color][/color]
'c'[color=blue][color=green][color=darkred]
>>>print txt[/color][/color][/color]
'a'
Question 1)
I guess that in Python ( differently than in C++) somehow txt is passed
by reference even if its value is not changed.
Is this true ?
Question 2)
How can I define a function that changes the value of txt ( without
having to return the changed value ) ?
Question 3)
Is there some documentation talking extensively about this ?
Thank you,
Marcello
My background is C++
I would like to know for sure if it is possible to pass a value by
reference to a function AND having it changed by the function itself
def changeValue( text ):
text = 'c'
print text
return
[color=blue][color=green][color=darkred]
>>> txt = 'a'
>>>changeValu e( txt )[/color][/color][/color]
'c'[color=blue][color=green][color=darkred]
>>>print txt[/color][/color][/color]
'a'
Question 1)
I guess that in Python ( differently than in C++) somehow txt is passed
by reference even if its value is not changed.
Is this true ?
Question 2)
How can I define a function that changes the value of txt ( without
having to return the changed value ) ?
Question 3)
Is there some documentation talking extensively about this ?
Thank you,
Marcello
Comment