Answers for "python unknow number of arguments, default argument,"

0

python unknow number of arguments, default argument,

def foo(a, b=3, *args, **kwargs):
  defaultKwargs = { 'c': 10, 'd': 12 }
  kwargs = { **defaultKwargs, **kwargs }
  print(a, b, args, kwargs)
  
  # Do something    

foo(1) # 1 3 () {'c': 10, 'd': 12}
foo(1, d=5) # 1 3 () {'c': 10, 'd': 5}
foo(1, 2, 4, d=5) # 1 2 (4,) {'c': 10, 'd': 5}
Posted by: Guest on September-25-2021

Code answers related to "python unknow number of arguments, default argument,"

Python Answers by Framework

Browse Popular Code Answers by Language