Browse Source

Partial

pull/36/head
Jure Šorn 5 years ago
parent
commit
21d2a03b8d
2 changed files with 6 additions and 0 deletions
  1. 2
      README.md
  2. 4
      index.html

2
README.md

@ -827,6 +827,8 @@ from functools import partial
>>> multiply_by_3(10)
30
```
* **Partial is useful in cases when a function needs to be passed as an argument, because it enables us to set the arguments beforehand.**
* **A few examples being `'defaultdict(<function>)'`, `'iter(<function>, to_exclusive)'` and dataclass's `'field(default_factory=<function>)'`.**
### Nonlocal
**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'.**

4
index.html

@ -801,6 +801,10 @@ creature = Creature(Point(<span class="hljs-number">0</span>, <span class="hljs
<span class="hljs-meta">&gt;&gt;&gt; </span>multiply_by_3(<span class="hljs-number">10</span>)
<span class="hljs-number">30</span>
</code></pre>
<ul>
<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>
<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>
</ul>
<h3 id="nonlocal">Nonlocal</h3>
<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>
<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>

Loading…
Cancel
Save