Skip to content

Commit 12738c8

Browse files
committed
Format
1 parent 20d5dc6 commit 12738c8

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ from itertools import count, repeat, cycle, chain, islice
212212
```python
213213
<iter> = islice(<collection>, to_exclusive)
214214
<iter> = islice(<collection>, from_inclusive, to_exclusive)
215-
<iter> = islice(<collection>, from_inclusive, to_exclusive, step_size)
215+
<iter> = islice(<collection>, from_inclusive, to_exclusive, +step_size)
216216
```
217217

218218

@@ -403,15 +403,15 @@ Format
403403
{<el>:>0} # '<el>'
404404
```
405405

406-
### String Options
406+
### Strings
407407
**`'!r'` calls object's repr() method, instead of format(), to get a string.**
408408
```python
409409
{'abcde'!r:<10} # "'abcde' "
410410
{'abcde':.3} # 'abc'
411411
{'abcde':10.3} # 'abc '
412412
```
413413

414-
### Number Options
414+
### Numbers
415415
```python
416416
{ 123456:10,} # ' 123,456'
417417
{ 123456:10_} # ' 123_456'
@@ -421,14 +421,30 @@ Format
421421
{-123456: } # '-123456'
422422
```
423423

424-
#### Float types:
424+
### Floats
425425
```python
426+
{1.23456:10.3} # ' 1.23'
426427
{1.23456:10.3f} # ' 1.235'
427428
{1.23456:10.3e} # ' 1.235e+00'
428429
{1.23456:10.3%} # ' 123.456%'
429430
```
430431

431-
#### Int types:
432+
```text
433+
+---------------+--------------+---------------+---------------+---------------+
434+
| | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
435+
+---------------+--------------+---------------+---------------+---------------+
436+
| 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |
437+
| 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |
438+
| 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |
439+
| 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |
440+
| 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |
441+
| 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |
442+
| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
443+
| 5678.9 | '5.7e+03' | '5678.90' | '5.68e+03' | '567890.00%' |
444+
+---------------+--------------+---------------+---------------+---------------+
445+
```
446+
447+
### Ints
432448
```python
433449
{90:c} # 'Z'
434450
{90:X} # '5A'

index.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ <h3 id="itertools">Itertools</h3>
343343
</code></pre>
344344
<pre><code class="python language-python hljs">&lt;iter&gt; = islice(&lt;collection&gt;, to_exclusive)
345345
&lt;iter&gt; = islice(&lt;collection&gt;, from_inclusive, to_exclusive)
346-
&lt;iter&gt; = islice(&lt;collection&gt;, from_inclusive, to_exclusive, step_size)
346+
&lt;iter&gt; = islice(&lt;collection&gt;, from_inclusive, to_exclusive, +step_size)
347347
</code></pre>
348348
<h2 id="generator"><a href="#generator" name="generator">#</a>Generator</h2>
349349
<p><strong>Convenient way to implement the iterator protocol.</strong></p>
@@ -480,26 +480,40 @@ <h3 id="generaloptions">General Options</h3>
480480
<pre><code class="python language-python hljs">{&lt;el&gt;:.&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># '&lt;el&gt;......'</span>
481481
{&lt;el&gt;:&gt;<span class="hljs-number">0</span>} <span class="hljs-comment"># '&lt;el&gt;'</span>
482482
</code></pre>
483-
<h3 id="stringoptions">String Options</h3>
483+
<h3 id="strings">Strings</h3>
484484
<p><strong><code class="python hljs"><span class="hljs-string">'!r'</span></code> calls object's repr() method, instead of format(), to get a string.</strong></p>
485485
<pre><code class="python language-python hljs">{<span class="hljs-string">'abcde'</span>!r:&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># "'abcde' "</span>
486486
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">.3</span>} <span class="hljs-comment"># 'abc'</span>
487487
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># 'abc '</span>
488488
</code></pre>
489-
<h3 id="numberoptions">Number Options</h3>
489+
<h3 id="numbers-1">Numbers</h3>
490490
<pre><code class="python language-python hljs">{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>,} <span class="hljs-comment"># ' 123,456'</span>
491491
{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>_} <span class="hljs-comment"># ' 123_456'</span>
492492
{ <span class="hljs-number">123456</span>:+<span class="hljs-number">10</span>} <span class="hljs-comment"># ' +123456'</span>
493493
{<span class="hljs-number">-123456</span>:=<span class="hljs-number">10</span>} <span class="hljs-comment"># '- 123456'</span>
494494
{ <span class="hljs-number">123456</span>: } <span class="hljs-comment"># ' 123456'</span>
495495
{<span class="hljs-number">-123456</span>: } <span class="hljs-comment"># '-123456'</span>
496496
</code></pre>
497-
<h4 id="floattypes">Float types:</h4>
498-
<pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span>
497+
<h3 id="floats">Floats</h3>
498+
<pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># ' 1.23'</span>
499+
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span>
499500
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>e} <span class="hljs-comment"># ' 1.235e+00'</span>
500501
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>%} <span class="hljs-comment"># ' 123.456%'</span>
501502
</code></pre>
502-
<h4 id="inttypes">Int types:</h4>
503+
<pre><code class="text language-text">+---------------+--------------+---------------+---------------+---------------+
504+
| | {&lt;float&gt;:.2} | {&lt;float&gt;:.2f} | {&lt;float&gt;:.2e} | {&lt;float&gt;:.2%} |
505+
+---------------+--------------+---------------+---------------+---------------+
506+
| 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |
507+
| 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |
508+
| 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |
509+
| 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |
510+
| 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |
511+
| 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |
512+
| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
513+
| 5678.9 | '5.7e+03' | '5678.90' | '5.68e+03' | '567890.00%' |
514+
+---------------+--------------+---------------+---------------+---------------+
515+
</code></pre>
516+
<h3 id="ints">Ints</h3>
503517
<pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span>
504518
{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span>
505519
{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span>

0 commit comments

Comments
 (0)