We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5a5be7b + 51a727d commit 2029979Copy full SHA for 2029979
docs/writing/gotchas.rst
@@ -166,6 +166,16 @@ its arguments by using a default arg like so:
166
def create_multipliers():
167
return [lambda x, i=i : i * x for i in range(5)]
168
169
+Alternatively, you can use the functools.partial function:
170
+
171
+.. code-block:: python
172
173
+ from functools import partial
174
+ from operator import mul
175
176
+ def create_multipliers():
177
+ return [partial(mul, i) for i in range(5)]
178
179
When the Gotcha Isn't a Gotcha
180
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181
0 commit comments