返回顶部

收藏

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)

标签:Python,Function

收藏

0人收藏

支持

0

反对

0