Answers for "optional arguments python string"


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
myfunc(a,b, c='nick', d='dog', ...)
#kwargs = dict of all the parameters that are key valued after a,b
Posted by: Guest on June-26-2021

Code answers related to "optional arguments python string"

Python Answers by Framework

Browse Popular Code Answers by Language