Using default arguments before positional arguments

后端 未结 3 2289
长情又很酷
长情又很酷 2021-02-13 15:18

I am learning to use positional arguments in python and also trying to see how they work when mixed up with default arguments:-

def withPositionalArgs(ae=9,*args         


        
3条回答
  •  耶瑟儿~
    2021-02-13 15:28

    In Python2, you are not allowed to put arguments which have a default value before positional arguments.

    The positional arguments must come first, then the arguments with default values (or, when calling the function, the keyword arguments), then *args, and then **kwargs.

    This order is required for both the function definition and for function calls.

    In Python3, the order has been relaxed. (For example, *args can come before a keyword argument in the function definition.) See PEP3102.

提交回复
热议问题