cpython: 44ca4264dc88 (original) (raw)

--- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -412,8 +412,8 @@ write the function like this instead:: Keyword Arguments ----------------- -Functions can also be called using keyword arguments of the form keyword =[](#l1.7) -value. For instance, the following function:: +Functions can also be called using :term:keyword arguments <keyword argument> +of the form kwarg=value. For instance, the following function:: def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): print("-- This parrot wouldn't", action, end=' ') @@ -421,26 +421,31 @@ value. For instance, the following fu[](#l1.14) print("-- Lovely plumage, the", type)[](#l1.15) print("-- It's", state, "!")[](#l1.16) [](#l1.17) -could be called in any of the following ways::[](#l1.18) +accepts one required argument (voltage) and three optional arguments[](#l1.19) +(state, action, and type``). This function can be called in any +of the following ways::

-but the following calls would all be invalid:: +but all the following calls would be invalid:: parrot() # required argument missing

-In general, an argument list must have any positional arguments followed by any -keyword arguments, where the keywords must be chosen from the formal parameter -names. It's not important whether a formal parameter has a default value or -not. No argument may receive a value more than once --- formal parameter names -corresponding to positional arguments cannot be used as keywords in the same -calls. Here's an example that fails due to this restriction:: +In a function call, keyword arguments must follow positional arguments. +All the keyword arguments passed must match one of the arguments +accepted by the function (e.g. actor is not a valid argument for the +parrot function), and their order is not important. This also includes +non-optional arguments (e.g. parrot(voltage=1000) is valid too). +No argument may receive a value more than once. +Here's an example that fails due to this restriction:: >>> def function(a): ... pass