Skip to content

Commit 1c920d1

Browse files
committed
Splat operator
1 parent dba864a commit 1c920d1

File tree

3 files changed

+35
-36
lines changed

3 files changed

+35
-36
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -705,23 +705,24 @@ func(1, 2, z=3)
705705
### Inside Function Definition
706706
**Splat combines zero or more positional arguments into a tuple, while splatty-splat combines zero or more keyword arguments into a dictionary.**
707707
```python
708-
>>> def add(*a):
709-
... return sum(a)
710-
...
708+
def add(*a):
709+
return sum(a)
710+
```
711+
712+
```python
711713
>>> add(1, 2, 3)
712714
6
713715
```
714716

715-
#### Allowed compositions of arguments inside function definition and the ways they can be called:
717+
#### Allowed compositions of arguments and the ways they can be called:
716718
```text
717-
+--------------------+------------+--------------+----------------+------------------+
718-
| | f(1, 2, 3) | f(1, 2, z=3) | f(1, y=2, z=3) | f(x=1, y=2, z=3) |
719-
+--------------------+------------+--------------+----------------+------------------+
720-
| f(x, *args, **kw): | yes | yes | yes | yes |
721-
| f(*args, z, **kw): | | yes | yes | yes |
722-
| f(x, **kw): | | | yes | yes |
723-
| f(*, x, **kw): | | | | yes |
724-
+--------------------+------------+--------------+----------------+------------------+
719+
+---------------------------+--------------+--------------+----------------+
720+
| | func(1, 2) | func(1, y=2) | func(x=1, y=2) |
721+
+---------------------------+--------------+--------------+----------------+
722+
| func(x, *args, **kwargs): | yes | yes | yes |
723+
| func(*args, y, **kwargs): | | yes | yes |
724+
| func(*, x, **kwargs): | | | yes |
725+
+---------------------------+--------------+--------------+----------------+
725726
```
726727

727728
### Other Uses

index.html

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<body>
5858
<header>
59-
<aside>April 30, 2025</aside>
59+
<aside>May 1, 2025</aside>
6060
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6161
</header>
6262

@@ -620,22 +620,21 @@
620620
<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>)
621621
</code></pre></div>
622622

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">&gt;&gt;&gt; </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">&gt;&gt;&gt; </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)
628625
</code></pre></div>
629626

630627

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">&gt;&gt;&gt; </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+
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
639638
</code></pre></div>
640639

641640
<div><h3 id="otheruses">Other Uses</h3><pre><code class="python language-python hljs">&lt;list&gt; = [*&lt;collection&gt; [, ...]] <span class="hljs-comment"># Or: list(&lt;coll&gt;) [+ ...]</span>
@@ -2940,7 +2939,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29402939

29412940

29422941
<footer>
2943-
<aside>April 30, 2025</aside>
2942+
<aside>May 1, 2025</aside>
29442943
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29452944
</footer>
29462945

parse.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,16 @@ const DIAGRAM_5_A =
424424
"+--------------+----------------+----------------+----------------+----------------+\n";
425425

426426
const DIAGRAM_55_A =
427-
"+--------------------+------------+--------------+----------------+------------------+\n";
427+
"+---------------------------+--------------+--------------+----------------+\n";
428428

429429
const DIAGRAM_55_B =
430-
'┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓\n' +
431-
'┃ │ 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>) ┃\n' +
432-
'┠────────────────────┼────────────┼──────────────┼────────────────┼──────────────────┨\n' +
433-
'┃ <span class="hljs-title">f</span>(x, *args, **kw): │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
434-
'┃ <span class="hljs-title">f</span>(*args, z, **kw): │ │ ✓ │ ✓ │ ✓ ┃\n' +
435-
'┃ <span class="hljs-title">f</span>(x, **kw): │ │ │ ✓ │ ✓ ┃\n' +
436-
'┃ <span class="hljs-title">f</span>(*, x, **kw): │ │ │ │ ✓ ┃\n' +
437-
'┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━┛\n';
430+
'┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓\n' +
431+
'┃ │ 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>) ┃\n' +
432+
'┠───────────────────────────┼──────────────┼──────────────┼────────────────┨\n' +
433+
'┃ <span class="hljs-title">func</span>(x, *args, **kwargs): │ ✓ │ ✓ │ ✓ ┃\n' +
434+
'┃ <span class="hljs-title">func</span>(*args, y, **kwargs): │ │ ✓ │ ✓ ┃\n' +
435+
'┃ <span class="hljs-title">func</span>(*, x, **kwargs): │ │ │ ✓ ┃\n' +
436+
'┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛\n';
438437

439438
const DIAGRAM_6_A =
440439
'+------------+------------+------------+------------+--------------+\n' +

0 commit comments

Comments
 (0)