Given a function:
def A(a, b, c):
a *= 2
b *= 4
c *= 8
return a+b+c
How can I set the ‘c’ var to be called-by-reference, so if i call d = A(a,b,c), c will point to the same int object, and be updated from within the function?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re getting into murky territory: you’re talking about declaring
global(ornonlocal) variables in functions, which should simply not be done. Functions are meant to do one thing, and do them without the consent of other values or functions affecting their state or output.It’s difficult to suggest a working example: are you alright with having copies of the variables left behind for later reference? You could expand this code to pass back a
tuple, and reference the members of thetupleif needed, or the sum: