From 12738c8764cbc3efd6c64b65f984bf64ca7f8a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 2 Jul 2019 00:31:20 +0200 Subject: [PATCH] Format --- README.md | 26 +++++++++++++++++++++----- index.html | 26 ++++++++++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index bef8bda..df1139d 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ from itertools import count, repeat, cycle, chain, islice ```python = islice(, to_exclusive) = islice(, from_inclusive, to_exclusive) - = islice(, from_inclusive, to_exclusive, step_size) + = islice(, from_inclusive, to_exclusive, +step_size) ``` @@ -403,7 +403,7 @@ Format {:>0} # '' ``` -### String Options +### Strings **`'!r'` calls object's repr() method, instead of format(), to get a string.** ```python {'abcde'!r:<10} # "'abcde' " @@ -411,7 +411,7 @@ Format {'abcde':10.3} # 'abc ' ``` -### Number Options +### Numbers ```python { 123456:10,} # ' 123,456' { 123456:10_} # ' 123_456' @@ -421,14 +421,30 @@ Format {-123456: } # '-123456' ``` -#### Float types: +### Floats ```python +{1.23456:10.3} # ' 1.23' {1.23456:10.3f} # ' 1.235' {1.23456:10.3e} # ' 1.235e+00' {1.23456:10.3%} # ' 123.456%' ``` -#### Int types: +```text ++---------------+--------------+---------------+---------------+---------------+ +| | {:.2} | {:.2f} | {:.2e} | {:.2%} | ++---------------+--------------+---------------+---------------+---------------+ +| 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' | +| 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' | +| 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' | +| 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' | +| 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' | +| 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' | +| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' | +| 5678.9 | '5.7e+03' | '5678.90' | '5.68e+03' | '567890.00%' | ++---------------+--------------+---------------+---------------+---------------+ +``` + +### Ints ```python {90:c} # 'Z' {90:X} # '5A' diff --git a/index.html b/index.html index ed23e22..9b4dec4 100644 --- a/index.html +++ b/index.html @@ -343,7 +343,7 @@ to_exclusive = <range>.stop
<iter> = islice(<collection>, to_exclusive)
 <iter> = islice(<collection>, from_inclusive, to_exclusive)
-<iter> = islice(<collection>, from_inclusive, to_exclusive, step_size)
+<iter> = islice(<collection>, from_inclusive, to_exclusive, +step_size)
 

#Generator

Convenient way to implement the iterator protocol.

@@ -480,13 +480,13 @@ to_exclusive = <range>.stop
{<el>:.<10}      # '<el>......'
 {<el>:>0}        # '<el>'
 
-

String Options

+

Strings

'!r' calls object's repr() method, instead of format(), to get a string.

{'abcde'!r:<10}  # "'abcde'   "
 {'abcde':.3}     # 'abc'
 {'abcde':10.3}   # 'abc       '
 
-

Number Options

+

Numbers

{ 123456:10,}    # '   123,456'
 { 123456:10_}    # '   123_456'
 { 123456:+10}    # '   +123456'
@@ -494,12 +494,26 @@ to_exclusive   = <range>.stop
 { 123456: }      # ' 123456'
 {-123456: }      # '-123456'
 
-

Float types:

-
{1.23456:10.3f}  # '     1.235'
+

Floats

+
{1.23456:10.3}   # '      1.23'
+{1.23456:10.3f}  # '     1.235'
 {1.23456:10.3e}  # ' 1.235e+00'
 {1.23456:10.3%}  # '  123.456%'
 
-

Int types:

+
+---------------+--------------+---------------+---------------+---------------+
+|               | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
++---------------+--------------+---------------+---------------+---------------+
+|    0.00056789 |  '0.00057'   |      '0.00'   |  '5.68e-04'   |      '0.06%'  |
+|    0.0056789  |  '0.0057'    |      '0.01'   |  '5.68e-03'   |      '0.57%'  |
+|    0.056789   |  '0.057'     |      '0.06'   |  '5.68e-02'   |      '5.68%'  |
+|    0.56789    |  '0.57'      |      '0.57'   |  '5.68e-01'   |     '56.79%'  |
+|    5.6789     |  '5.7'       |      '5.68'   |  '5.68e+00'   |    '567.89%'  |
+|   56.789      |  '5.7e+01'   |     '56.79'   |  '5.68e+01'   |   '5678.90%'  |
+|  567.89       |  '5.7e+02'   |    '567.89'   |  '5.68e+02'   |  '56789.00%'  |
+| 5678.9        |  '5.7e+03'   |   '5678.90'   |  '5.68e+03'   | '567890.00%'  |
++---------------+--------------+---------------+---------------+---------------+
+
+

Ints

{90:c}           # 'Z'
 {90:X}           # '5A'
 {90:b}           # '1011010'