In Python, what determines the order while iterating through kwargs?

前端 未结 6 1290
悲&欢浪女
悲&欢浪女 2020-12-03 17:45

In python, I wrote this function to teach myself how **kwargs works in Python:

def fxn(a1, **kwargs):
    print a1
    for k in kwargs:
                 


        
6条回答
  •  眼角桃花
    2020-12-03 18:29

    This has finally been introduced in the 3.6 release: dicts are now ordered, therefore the keyword argument order is preserved.

    Python 3.6.0 (default, Jan 13 2017, 13:27:48) 
    >>> def print_args(**kwargs):
    ...     print(kwargs.keys())
    ... 
    >>> print_args(first=1, second=2, third=3)
    dict_keys(['first', 'second', 'third'])
    

提交回复
热议问题