0

what is the simplest way to pass two variables to a function in Python and get two variables back from the function

thanks in advance.

ninja
  • 41
  • 1
  • 1
  • 1
  • 1
    @ninja `fnct(a, b): return c, d`. `x, y = fnct(a, b)` – Kenly Dec 06 '15 at 13:51
  • see official faq docs https://docs.python.org/2.7/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference – pigletfly Dec 06 '15 at 13:55

2 Answers2

2

You write a function that takes 2 inputs, and return a comma separated list of outputs:

def function(first, second):
    return first, second

firstOutput, secondOutput = function(1,2)
Simon
  • 9,762
  • 15
  • 62
  • 119
1

You could make a definition that takes 2 values as an input, and have a return below that that returns 2 values.

For example:

#Create a definition 
def HelloWorld(valueA, valueB):
    print(valueA)
    print(valueB) 
    return 'Hello', 'World'


# Call the definition 
HelloWorld('HelloA', 'HelloB')
Tenzin
  • 2,415
  • 2
  • 23
  • 36