Answers for "optional arguments python"

10

python optional arguments

def myfunc(a,b, *args, **kwargs):
      c = kwargs.get('c', None)
      d = kwargs.get('d', None)
      #etc
myfunc(a,b, c='nick', d='dog', ...)
Posted by: Guest on February-10-2020
13

python optional parameters

def my_func(a = 1, b = 2, c = 3):
	print(a + b + c)
    
my_func()
#OUTPUT = 6

my_func(2)
#This changes the value of a to 2
#OUTPUT = 7

my_func(c = 2)
#This changes the value of c to 2
#OUTPUT = 5
Posted by: Guest on July-30-2020
2

make parameter optional python

def myfunc(a,b, *args, **kwargs):
   for ar in args:
      print ar
myfunc(a,b,c,d,e,f)
Posted by: Guest on February-04-2021
3

python create a function with optional parameter

def some_function (self, a, b, c, d = None, e = None, f = None, g = None, h = None):
    #code
Posted by: Guest on May-08-2020
0

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
Posted by: Guest on June-26-2021
1

optional arguments python

def some_function (self, a, b, c, d = None, e = None, f = None, g = None, h = None):
    #code
Posted by: Guest on December-15-2020

Code answers related to "optional arguments python"

Python Answers by Framework

Browse Popular Code Answers by Language