3

Assume I have the following function:

def func(a, b=0, c=1, d=2,...):
# Code goes here

I want to use it inside another function like this:

def do_sth(...):
   func(...)

do_sth(...)

The number of parameters of func is big. What should I do to pass (optional) params to func when calling do_sth, because the following method is usable but not pythonic:

def do_sth(a, b, c...):
   func(a=a, b=b,c=c...)

do_sth(a, b, c...)
Minh-Long Luu
  • 2,393
  • 1
  • 17
  • 39

1 Answers1

3

Pass a dictionary like this (using ** before params dict):

params = {
   'a': 1,
   'b': 2,
   'c': 3,
   'd': 4
}
func(**params)

To pass list, use *:

params = [1,2,3,4]
func(*params)
Wasif
  • 14,755
  • 3
  • 14
  • 34