@@ -66,63 +66,6 @@ Line 2
6666Line 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:
0 commit comments