pythonsyntax

Python meta/unpacking in a function


I have a function (func1) that returns a 4-tuple of mixed strings and integers. I want to immediately pass these 4 values into a second function (func2). This is how I am doing it now:

var1, var2, var3, var4 = func1(input1)
func2(var1, var2, var3, var4)

Functions don't unpack tuples when given as input, so this code is broken:

func2(func1(input1))

Is there a pythonic way to implement this code in the style of the second code block so func2 will unpack the values or some equivalent?


Solution

  • Use the * operator:

    func2(*func1(input1))