Skip to content

Commit 21d2a03

Browse files
committed
Partial
1 parent a5529ae commit 21d2a03

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ from functools import partial
827827
>>> multiply_by_3(10)
828828
30
829829
```
830+
* **Partial is useful in cases when a function needs to be passed as an argument, because it enables us to set the arguments beforehand.**
831+
* **A few examples being `'defaultdict(<function>)'`, `'iter(<function>, to_exclusive)'` and dataclass's `'field(default_factory=<function>)'`.**
830832

831833
### Nonlocal
832834
**If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.**

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ <h3 id="partial">Partial</h3>
801801
<span class="hljs-meta">&gt;&gt;&gt; </span>multiply_by_3(<span class="hljs-number">10</span>)
802802
<span class="hljs-number">30</span>
803803
</code></pre>
804+
<ul>
805+
<li><strong>Partial is useful in cases when a function needs to be passed as an argument, because it enables us to set the arguments beforehand.</strong></li>
806+
<li><strong>A few examples being <code class="python hljs"><span class="hljs-string">'defaultdict(&lt;function&gt;)'</span></code>, <code class="python hljs"><span class="hljs-string">'iter(&lt;function&gt;, to_exclusive)'</span></code> and dataclass's <code class="python hljs"><span class="hljs-string">'field(default_factory=&lt;function&gt;)'</span></code>.</strong></li>
807+
</ul>
804808
<h3 id="nonlocal">Nonlocal</h3>
805809
<p><strong>If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.</strong></p>
806810
<pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_counter</span><span class="hljs-params">()</span>:</span>

0 commit comments

Comments
 (0)