0

I have a list of variables that need to be passed in a couple of functions that take the same number of arguments.

a = 1
b = 'hello'
c = 1.9

args = (a, b, c)

op = func_a(args) if <cond1> else func_b(args)

def func_a(a, b, c):
    ...
    
def func_b(a, b, c):
    ...

But sending this as a tuple, the tuple is set to arg a and the function expects args b and c as well.

How can I pass these tuple as a, b, and crespectively?

Azima
  • 3,835
  • 15
  • 49
  • 95
  • Does this answer your question? [Expanding tuples into arguments](https://stackoverflow.com/questions/1993727/expanding-tuples-into-arguments) – JonSG Feb 06 '23 at 13:55

1 Answers1

1

Use * to unpack the tuple:

op = func_a(*args) if <cond1> else func_b(*args)

This will unpack the tuple and pass the parameters as separate arguments.

sagi
  • 40,026
  • 6
  • 59
  • 84