Skip to content

Commit 5b53665

Browse files
committed
📝 Rearrange functions section
1 parent 37d66b2 commit 5b53665

File tree

3 files changed

+55
-57
lines changed

3 files changed

+55
-57
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Changed
2727
~~~~~~~
2828

2929
* 📝 Expand the pytest plugins section
30+
* 📝 Rearrange functions section
3031
* 🎨 Restructure the documentation
3132

3233
* Move packages outside libraries

docs/functions/index.rst

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -66,63 +66,6 @@ Line 2
6666
Line 3
6767
The return value is linked to the variable ``x``.
6868

69-
Parameters
70-
----------
71-
72-
Python offers flexible mechanisms for passing arguments to functions:
73-
74-
.. code-block:: pycon
75-
:linenos:
76-
77-
>>> x, y = 2, 3
78-
>>> def func1(u, v, w):
79-
... value = u + 2 * v + w**2
80-
... if value > 0:
81-
... return u + 2 * v + w**2
82-
... else:
83-
... return 0
84-
...
85-
>>> func1(x, y, 2)
86-
12
87-
>>> func1(x, w=y, v=2)
88-
15
89-
>>> def func2(u, v=1, w=1):
90-
... return u + 4 * v + w**2
91-
...
92-
>>> func2(5, w=6)
93-
45
94-
>>> def func3(u, v=1, w=1, *tup):
95-
... print((u, v, w) + tup)
96-
...
97-
>>> func3(7)
98-
(7, 1, 1)
99-
>>> func3(1, 2, 3, 4, 5)
100-
(1, 2, 3, 4, 5)
101-
>>> def func4(u, v=1, w=1, **kwargs):
102-
... print(u, v, w, kwargs)
103-
...
104-
>>> func4(1, 2, s=4, t=5, w=3)
105-
1 2 3 {'s': 4, 't': 5}
106-
107-
Line 2
108-
Functions are defined with the ``def`` statement.
109-
Line 5
110-
The ``return`` statement is used by a function to return a value. This value
111-
can be of any type. If no ``return`` statement is found, the value ``None``
112-
is returned by Python.
113-
Line 11
114-
Function arguments can be entered either by position or by name (keyword).
115-
``z`` and ``y`` are specified by name in our example.
116-
Line 13
117-
Function parameters can be defined with default values that will be used if
118-
a function call omits them.
119-
Line 18
120-
A special parameter can be defined that combines all additional positional
121-
arguments in a function call into one tuple.
122-
Line 25
123-
Similarly, a special parameter can be defined that summarises all additional
124-
keyword arguments in a function call in a dictionary.
125-
12669
.. toctree::
12770
:titlesonly:
12871
:hidden:

docs/functions/params.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
11
Parameters
22
==========
33

4+
Python offers flexible mechanisms for passing arguments to functions:
5+
6+
.. code-block:: pycon
7+
:linenos:
8+
9+
>>> x, y = 2, 3
10+
>>> def func1(u, v, w):
11+
... value = u + 2 * v + w**2
12+
... if value > 0:
13+
... return u + 2 * v + w**2
14+
... else:
15+
... return 0
16+
...
17+
>>> func1(x, y, 2)
18+
12
19+
>>> func1(x, w=y, v=2)
20+
15
21+
>>> def func2(u, v=1, w=1):
22+
... return u + 4 * v + w**2
23+
...
24+
>>> func2(5, w=6)
25+
45
26+
>>> def func3(u, v=1, w=1, *tup):
27+
... print((u, v, w) + tup)
28+
...
29+
>>> func3(7)
30+
(7, 1, 1)
31+
>>> func3(1, 2, 3, 4, 5)
32+
(1, 2, 3, 4, 5)
33+
>>> def func4(u, v=1, w=1, **kwargs):
34+
... print(u, v, w, kwargs)
35+
...
36+
>>> func4(1, 2, s=4, t=5, w=3)
37+
1 2 3 {'s': 4, 't': 5}
38+
39+
Line 2
40+
Functions are defined with the ``def`` statement.
41+
Line 5
42+
The ``return`` statement is used by a function to return a value. This value
43+
can be of any type. If no ``return`` statement is found, the value ``None``
44+
is returned by Python.
45+
Line 11
46+
Function arguments can be entered either by position or by name (keyword).
47+
``z`` and ``y`` are specified by name in our example.
48+
Line 13
49+
Function parameters can be defined with default values that will be used if
50+
a function call omits them.
51+
Line 18
52+
A special parameter can be defined that combines all additional positional
53+
arguments in a function call into one tuple.
54+
Line 25
55+
Similarly, a special parameter can be defined that summarises all additional
56+
keyword arguments in a function call in a dictionary.
57+
458
Options for function parameters
559
-------------------------------
660

0 commit comments

Comments
 (0)