-1

How to pass parameters into function incrementally(?), like:

def func(a, b="string0", c=False):
    print(f"a={str(a)}, b={str(b)}, c={str(c)}")

a=1
b="string"
c=True

params = [[a], [a, b], [a, b, c]]

for par in params:
    func(par)

current output:

a=[1], b=string0, c=False
a=[1, 'string'], b=string0, c=False
a=[1, 'string', True], b=string0, c=False

is not, that I wanted. It should trigger each actual parameter of the function according to passed number of arguments. Should behave, like:

func(a)
func(a, b)
func(a, b, c)
Gen Eva
  • 39
  • 6

1 Answers1

2

Use list unpacking as described in this question:

for par in params:
    func(*par)

This will unpack the list into consecutive arguments.

matszwecja
  • 6,357
  • 2
  • 10
  • 17
  • Thanks! I am new to python, so came for this problem directly, rather from syntax and language specification first – Gen Eva Apr 18 '23 at 11:45