3 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
def my_function(arg1, arg2, **kwargs)
def my_function(**kwargs): print str(kwargs)my_function(a=12, b="abc"){'a': 12, 'b': 'abc'}

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
def foo(*positional, **keywords): print "Positional:", positional print "Keywords:", keywords
*positional
foo()
>>> foo('one', 'two', 'three')Positional: ('one', 'two', 'three')Keywords: {}
**keywords
>>> foo(a='one', b='two', c='three')Positional: ()Keywords: {'a': 'one', 'c': 'three', 'b': 'two'}
>>> foo('one','two',c='three',d='four')Positional: ('one', 'two')Keywords: {'c': 'three', 'd': 'four'}

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
def foo(bar, baz): passfoo(1, 2)foo(baz=2, bar=1)
添加回答
舉報(bào)