1def myfunc(a,b, *args, **kwargs):
2 c = kwargs.get('c', None)
3 d = kwargs.get('d', None)
4 #etc
5myfunc(a,b, c='nick', d='dog', ...)
1def my_func(a = 1, b = 2, c = 3):
2 print(a + b + c)
3
4my_func()
5#OUTPUT = 6
6
7my_func(2)
8#This changes the value of a to 2
9#OUTPUT = 7
10
11my_func(c = 2)
12#This changes the value of c to 2
13#OUTPUT = 5
1def myfunc(a,b, *args, **kwargs):
2 for ar in args:
3 print ar
4myfunc(a,b,c,d,e,f)
5
1def some_function (self, a, b, c, d = None, e = None, f = None, g = None, h = None):
2 #code
1def myfunc(a,b, *args, **kwargs):
2 for ar in args:
3 print ar
4myfunc(a,b,c,d,e,f) #prints values of c,d,e,f
5
6def myfunc(a,b, *args, **kwargs):
7 c = kwargs.get('c', None) #test if 'c' defined
8 d = kwargs.get('d', None) #otherwise, return None
9 #etc
10myfunc(a,b, c='nick', d='dog', ...)
11#kwargs = dict of all the parameters that are key valued after a,b
1def myfunc(a,b, *args, **kwargs):
2 c = kwargs.get('c', None)
3 d = kwargs.get('d', None)
4 #etc
5myfunc(a,b, c='nick', d='dog', ...)
6