Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

optional arguments python

def myfunc(a,b, *args, **kwargs):
   for ar in args:
      print ar
myfunc(a,b,c,d,e,f) #prints values of c,d,e,f

def myfunc(a,b, *args, **kwargs):
      c = kwargs.get('c', None) #test if 'c' defined
      d = kwargs.get('d', None) #otherwise, return None
      #etc
myfunc(a,b, c='nick', d='dog', ...)
#kwargs = dict of all the parameters that are key valued after a,b
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #optional #arguments #python
ADD COMMENT
Topic
Name
4+5 =