|
56 | 56 |
|
57 | 57 | <body> |
58 | 58 | <header> |
59 | | - <aside>April 30, 2025</aside> |
| 59 | + <aside>May 1, 2025</aside> |
60 | 60 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
61 | 61 | </header> |
62 | 62 |
|
|
620 | 620 | <div><h4 id="isthesameas">Is the same as:</h4><pre><code class="python language-python hljs">func(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, z=<span class="hljs-number">3</span>) |
621 | 621 | </code></pre></div> |
622 | 622 |
|
623 | | -<div><h3 id="insidefunctiondefinition">Inside Function Definition</h3><p><strong>Splat combines zero or more positional arguments into a tuple, while splatty-splat combines zero or more keyword arguments into a dictionary.</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">(*a)</span>:</span> |
624 | | -<span class="hljs-meta">... </span> <span class="hljs-keyword">return</span> sum(a) |
625 | | -<span class="hljs-meta">... </span> |
626 | | -<span class="hljs-meta">>>> </span>add(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) |
627 | | -<span class="hljs-number">6</span> |
| 623 | +<div><h3 id="insidefunctiondefinition">Inside Function Definition</h3><p><strong>Splat combines zero or more positional arguments into a tuple, while splatty-splat combines zero or more keyword arguments into a dictionary.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">(*a)</span>:</span> |
| 624 | + <span class="hljs-keyword">return</span> sum(a) |
628 | 625 | </code></pre></div> |
629 | 626 |
|
630 | 627 |
|
631 | | -<div><h4 id="allowedcompositionsofargumentsinsidefunctiondefinitionandthewaystheycanbecalled">Allowed compositions of arguments inside function definition and the ways they can be called:</h4><pre><code class="text language-text">┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓ |
632 | | -┃ │ f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) │ f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, z=<span class="hljs-number">3</span>) │ f(<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>, z=<span class="hljs-number">3</span>) │ f(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>, z=<span class="hljs-number">3</span>) ┃ |
633 | | -┠────────────────────┼────────────┼──────────────┼────────────────┼──────────────────┨ |
634 | | -┃ <span class="hljs-title">f</span>(x, *args, **kw): │ ✓ │ ✓ │ ✓ │ ✓ ┃ |
635 | | -┃ <span class="hljs-title">f</span>(*args, z, **kw): │ │ ✓ │ ✓ │ ✓ ┃ |
636 | | -┃ <span class="hljs-title">f</span>(x, **kw): │ │ │ ✓ │ ✓ ┃ |
637 | | -┃ <span class="hljs-title">f</span>(*, x, **kw): │ │ │ │ ✓ ┃ |
638 | | -┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━┛ |
| 628 | +<pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>add(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) |
| 629 | +<span class="hljs-number">6</span> |
| 630 | +</code></pre> |
| 631 | +<div><h4 id="allowedcompositionsofargumentsandthewaystheycanbecalled">Allowed compositions of arguments and the ways they can be called:</h4><pre><code class="text language-text">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓ |
| 632 | +┃ │ func(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>) │ func(<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>) │ func(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>) ┃ |
| 633 | +┠───────────────────────────┼──────────────┼──────────────┼────────────────┨ |
| 634 | +┃ <span class="hljs-title">func</span>(x, *args, **kwargs): │ ✓ │ ✓ │ ✓ ┃ |
| 635 | +┃ <span class="hljs-title">func</span>(*args, y, **kwargs): │ │ ✓ │ ✓ ┃ |
| 636 | +┃ <span class="hljs-title">func</span>(*, x, **kwargs): │ │ │ ✓ ┃ |
| 637 | +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛ |
639 | 638 | </code></pre></div> |
640 | 639 |
|
641 | 640 | <div><h3 id="otheruses">Other Uses</h3><pre><code class="python language-python hljs"><list> = [*<collection> [, ...]] <span class="hljs-comment"># Or: list(<coll>) [+ ...]</span> |
@@ -2940,7 +2939,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2940 | 2939 |
|
2941 | 2940 |
|
2942 | 2941 | <footer> |
2943 | | - <aside>April 30, 2025</aside> |
| 2942 | + <aside>May 1, 2025</aside> |
2944 | 2943 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2945 | 2944 | </footer> |
2946 | 2945 |
|
|
0 commit comments