Default arguments with *args and **kwargs

前端 未结 7 1294
刺人心
刺人心 2020-11-27 12:12

In Python 2.x (I use 2.7), which is the proper way to use default arguments with *args and **kwargs?
I\'ve found a question on

7条回答
  •  误落风尘
    2020-11-27 12:54

    The syntax in the other question is python3.x only and specifies keyword only arguments. It doesn't work on python2.x.

    For python2.x, I would pop it out of kwargs:

    def func(arg1, arg2, *args, **kwargs):
        opt_arg = kwargs.pop('opt_arg', 'def_val')
    

提交回复
热议问题