Dmitry Zakharov
Dmitry Zakharov

Reputation: 13

Returning 2 values in a function

In a nutshell, I'm trying to implement the following:

def function_one(value):
...
return a, b

def function_two(a, b):
...

And when I try

function_two(function_one(value))

I get an error message: "function_two() missing 1 required positional argument: 'b'"

Is there a way to make this work as intended? Thanks!

Upvotes: 1

Views: 57

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318788

You have to unpack the tuple you return into separate arguments:

function_two(*function_one(value))

Another option would be changing function_two to accept a single argument and then unpack it inside the function or use it as-is. Whether this is a good idea or not depends on the context.

Upvotes: 5

Related Questions