Function parameters: using the double asterisk operator : Function Dictionary Parameters « Function « Python






Function parameters: using the double asterisk operator

Function parameters: using the double asterisk operator

def add(x, y): return x + y

params = (1, 2)

add(*params)


params = {'name': 'Sir Robin', 'greeting': 'Well met'}

def with_stars(**kwds):
        print kwds['name'], 'is', kwds['age'], 'years old'

def without_stars(kwds):
        print kwds['name'], 'is', kwds['age'], 'years old'

args = {'name': 'Mr. Joe', 'age': 42}
with_stars(**args)

without_stars(args)
           
       








Related examples in the same category

1.Turn parameters into a dictionaryTurn parameters into a dictionary
2.Collecting ParametersCollecting Parameters
3.Parameter passing: mixed with dictionary and tupleParameter passing: mixed with dictionary and tuple