0

As a very basic example of what I want to do, I want to update the values 1 and 2, after running them through the example method. Like how you would use ref for Java.

def example(value1, value2):
    value1 += 2
    value2 += 4

value1 = 0
value2 = 0

example(value1, value2)
print(str(value1))
print(str(value1))
Grimat
  • 49
  • 1
  • 8

1 Answers1

0

You don't you need to return them

def example(value1, value2):
    value1 += 2
    value2 += 4
    return (value1, value2)

>>> value1 = 0
>>> value2 = 0
>>> value1, value2 = example(value1, value2)
>>> print(value1, value2)
2 4

You can only do what you are asking if the passed-in type is mutable, which an int is not.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • Well I needed the value as an int, so I've just repeated the code in my project. Thanks for helping :) – Grimat Jun 16 '15 at 04:20