Normal arguments vs. keyword arguments

后端 未结 10 845
一个人的身影
一个人的身影 2020-11-22 02:35

How are \"keyword arguments\" different from regular arguments? Can\'t all arguments be passed as name=value instead of using positional syntax?

10条回答
  •  耶瑟儿~
    2020-11-22 02:47

    There are two ways to assign argument values to function parameters, both are used.

    1. By Position. Positional arguments do not have keywords and are assigned first.

    2. By Keyword. Keyword arguments have keywords and are assigned second, after positional arguments.

    Note that you have the option to use positional arguments.

    If you don't use positional arguments, then -- yes -- everything you wrote turns out to be a keyword argument.

    When you call a function you make a decision to use position or keyword or a mixture. You can choose to do all keywords if you want. Some of us do not make this choice and use positional arguments.

提交回复
热议问题