python unknow number of arguments 2c default argument 2c

Solutions on MaxInterview for python unknow number of arguments 2c default argument 2c by the best coders in the world

showing results for - "python unknow number of arguments 2c default argument 2c"
Philipp
10 Oct 2020
1def foo(a, b=3, *args, **kwargs):
2  defaultKwargs = { 'c': 10, 'd': 12 }
3  kwargs = { **defaultKwargs, **kwargs }
4  print(a, b, args, kwargs)
5  
6  # Do something    
7
8foo(1) # 1 3 () {'c': 10, 'd': 12}
9foo(1, d=5) # 1 3 () {'c': 10, 'd': 5}
10foo(1, 2, 4, d=5) # 1 2 (4,) {'c': 10, 'd': 5}
11
similar questions