@@ -47,29 +47,30 @@ Line 11
4747 Function arguments can be entered either by position or by name (keyword).
4848 ``z `` and ``y `` are specified by name in our example.
4949Line 13
50- Function parameters can be defined with default values that will be used if
51- a function call omits them.
50+ Function :term: ` parameters <Parameter> ` can be defined with default values
51+ that will be used if a function call omits them.
5252Line 18
53- A special parameter can be defined that combines all additional positional
54- arguments in a function call into one tuple.
53+ A special :term: ` parameter ` can be defined that combines all additional
54+ positional arguments in a function call into one tuple.
5555Line 25
56- Similarly, a special parameter can be defined that summarises all additional
57- keyword arguments in a function call in a dictionary.
56+ Similarly, a special :term: ` parameter ` can be defined that summarises all
57+ additional keyword arguments in a function call in a dictionary.
5858
5959Options for function parameters
6060-------------------------------
6161
62- Most functions need parameters. Python offers three options for defining
63- function parameters.
62+ Most functions need :term: ` parameters <Parameter> ` . Python offers three options
63+ for defining function parameters.
6464
6565Positional parameters
6666~~~~~~~~~~~~~~~~~~~~~
6767
68- The simplest way to pass parameters to a function in Python is to pass them at
69- the position. On the first line of the function, you specify the variable name
70- for each parameter; when the function is called, the parameters used in the
71- calling code are assigned to the function’s parameter variables based on their
72- order. The following function calculates ``x `` as a power of ``y ``:
68+ The simplest way to pass :term: `parameters <Parameter> ` to a function in Python
69+ is to pass them at the position. On the first line of the function, you specify
70+ the variable name for each parameter; when the function is called, the
71+ parameters used in the calling code are assigned to the function’s parameter
72+ variables based on their order. The following function calculates ``x `` as a
73+ power of ``y ``:
7374
7475.. code-block :: pycon
7576
@@ -83,9 +84,9 @@ order. The following function calculates ``x`` as a power of ``y``:
8384 >>> power(2, 5)
8485 32
8586
86- This method requires that the number of parameters used by the calling code
87- exactly matches the number of parameters in the function definition; otherwise,
88- a type error exception is thrown:
87+ This method requires that the number of :term: ` parameters <Parameter> ` used by
88+ the calling code exactly matches the number of parameters in the function
89+ definition; otherwise, a type error exception is thrown:
8990
9091.. code-block :: pycon
9192
@@ -94,15 +95,17 @@ a type error exception is thrown:
9495 File "<stdin>", line 1, in <module>
9596 TypeError: power() missing 1 required positional argument: 'y'
9697
97- Function parameters can have default values, which you can declare by assigning
98- a default value in the first line of the function definition, like this:
98+ Function :term: `parameters <Parameter> ` can have default values, which you can
99+ declare by assigning a default value in the first line of the function
100+ definition, like this:
99101
100102.. code-block :: pycon
101103
102104 def function_name(param1, param2=Standardwert2, param3=Standardwert3, ...)
103105
104- Any number of parameters can be given default values, but parameters with
105- default values must be defined as the last in the parameter list.
106+ Any number of :term: `parameters <Parameter> ` can be given default values, but
107+ parameters with default values must be defined as the last in the parameter
108+ list.
106109
107110The following function also calculates ``x `` as a power of ``y ``. However, if
108111``y `` is not specified in a function call, the default value ``5 `` is used:
@@ -130,7 +133,7 @@ Parameter names
130133~~~~~~~~~~~~~~~
131134
132135You can also pass arguments to a function by using the name of the corresponding
133- function parameter rather than its position. Similar to the previous example,
136+ function :term: ` parameter ` rather than its position. Similar to the previous example,
134137you can enter the following:
135138
136139.. code-block :: pycon
@@ -139,12 +142,12 @@ you can enter the following:
139142 64
140143
141144 Since the arguments for the power are named ``x `` and ``y `` in the last call,
142- their order is irrelevant; the arguments are linked to the parameters of the
143- same name in the definition of the power, and you get back `` 2^6 ``. This type of
144- argument passing is called keyword passing. Keyword passing can be very useful
145- in combination with the default arguments of Python functions when you define
146- functions with a large number of possible arguments, most of which have common
147- default values.
145+ their order is irrelevant; the arguments are linked to the :term: ` parameters
146+ <Parameter> ` of the same name in the definition of the power, and you get back
147+ `` 2^6 ``. This type of argument passing is called keyword passing. Keyword
148+ passing can be very useful in combination with the default arguments of Python
149+ functions when you define functions with a large number of possible arguments,
150+ most of which have common default values.
148151
149152Variable number of arguments
150153~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -153,14 +156,15 @@ Python functions can also be defined to handle a variable number of arguments.
153156This is possible in two ways. One method collects an unknown number of arguments
154157in a :doc: `list </types/sequences-sets/lists >`. The other method can collect an
155158arbitrary number of arguments passed with a keyword that has no correspondingly
156- named parameter in the function parameter list in a :doc: `dict </types/dicts >`.
159+ named :term: `parameter ` in the function parameter list in a :doc: `dict
160+ </types/dicts>`.
157161
158162For an indeterminate number of positional arguments, prefixing the function’s
159- final parameter name with a ``* `` causes all excess non-keyword arguments in a
160- function call, that is, the positional arguments that are not assigned to any
161- other parameter, to be collected and assigned as a tuple to the specified
162- parameter. This is, for example, a simple way to implement a function that finds
163- the mean in a list of numbers:
163+ final :term: ` parameter ` name with a ``* `` causes all excess non-keyword
164+ arguments in a function call, that is, the positional arguments that are not
165+ assigned to any other parameter, to be collected and assigned as a tuple to the
166+ specified parameter. This is, for example, a simple way to implement a function
167+ that finds the mean in a list of numbers:
164168
165169.. code-block :: pycon
166170
@@ -179,13 +183,14 @@ Now you can test the behaviour of the function, for example with:
179183 >>> mean(3, 5, 2, 4, 6)
180184 4.0
181185
182- Any number of keyword arguments can also be processed if the last parameter in
183- the parameter list is prefixed with ``** ``. Then all arguments passed with a
184- keyword are collected in a :doc: `dict </types/dicts >`. The key for each entry in
185- the dict is the keyword (parameter name) for the argument. The value of this
186- entry is the argument itself. An argument passed by keyword is superfluous in
187- this context if the keyword with which it was passed does not match one of the
188- parameter names in the function definition, for example:
186+ Any number of keyword arguments can also be processed if the last
187+ :term: `parameter ` in the parameter list is prefixed with ``** ``. Then all
188+ arguments passed with a keyword are collected in a :doc: `dict </types/dicts >`.
189+ The key for each entry in the dict is the keyword (parameter name) for the
190+ argument. The value of this entry is the argument itself. An argument passed by
191+ keyword is superfluous in this context if the keyword with which it was passed
192+ does not match one of the parameter names in the function definition, for
193+ example:
189194
190195.. code-block :: pycon
191196
@@ -203,7 +208,7 @@ parameter names in the function definition, for example:
203208
204209 Trying out this function shows that it can add the arguments passed under the
205210keywords ``foo ``, ``bar `` and ``baz ``, even though ``foo ``, ``bar `` and ``baz ``
206- are not parameter names in the function definition:
211+ are not :term: ` parameter ` names in the function definition:
207212
208213.. code-block :: pycon
209214
@@ -223,11 +228,11 @@ keyword arguments with ``**``.
223228Mutable objects as arguments
224229----------------------------
225230
226- Arguments are passed by object reference. The parameter becomes a new reference
227- to the object. With :term: `immutable ` objects such as
231+ Arguments are passed by object reference. The :term: ` parameter ` becomes a new
232+ reference to the object. With :term: `immutable ` objects such as
228233:doc: `/types/sequences-sets/tuples `, :doc: `/types/strings/index ` and
229- :doc: `/types/numbers/index `, what is done with a parameter has no effect
230- outside the function. However, if you pass a mutable object, such as a
234+ :doc: `/types/numbers/index `, what is done with a parameter has no effect outside
235+ the function. However, if you pass a mutable object, such as a
231236:doc: `/types/sequences-sets/lists `, a :doc: `/types/dicts ` or a class instance,
232237any change to the object changes what the argument refers to outside the
233238function. Reassigning the parameter has no effect on the argument.
@@ -245,9 +250,9 @@ function. Reassigning the parameter has no effect on the argument.
245250 (5, [2, 4, 6, 1])
246251
247252 The variable ``x `` is not changed because it is :term: `immutable `. Instead, the
248- function parameter ``n `` is set so that it refers to the new value `` 6 ``.
249- However, there is a change in ``y `` because the list it refers to has been
250- changed.
253+ function :term: ` parameter ` ``n `` is set so that it refers to the new value
254+ `` 6 ``. However, there is a change in ``y `` because the list it refers to has
255+ been changed.
251256
252257Checks
253258------
0 commit comments