What is the purpose and use of **kwargs?

前端 未结 13 2657
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 04:59

What are the uses for **kwargs in Python?

I know you can do an objects.filter on a table and pass in a **kwargs argument. &nbs

13条回答
  •  清歌不尽
    2020-11-21 05:42

    As an addition, you can also mix different ways of usage when calling kwargs functions:

    def test(**kwargs):
        print kwargs['a']
        print kwargs['b']
        print kwargs['c']
    
    
    args = { 'b': 2, 'c': 3}
    
    test( a=1, **args )
    

    gives this output:

    1
    2
    3
    

    Note that **kwargs has to be the last argument

提交回复
热议问题