diff --git a/README.md b/README.md index 9054b86..ee4e421 100644 --- a/README.md +++ b/README.md @@ -392,9 +392,8 @@ import re Format ------ ```python - = f'{}, {}' # Curly braces also accept expressions. - = '{}, {}'.format(, ) # Or: '{0}, {1}'.format(, ) - = '%s, %s' % (, ) # Redundant and inferior C style formatting. + = f'{}, {}' # Or: '{}, {}'.format(, ) + = '%s, %s' % (, ) # Redundant and inferior C style formatting. ``` ### Attributes @@ -409,40 +408,40 @@ Format ### General Options ```python -{:<10} # ' ' -{:^10} # ' ' -{:>10} # ' ' -{:.<10} # '......' -{:0} # '' +{:<10} # ' ' +{:^10} # ' ' +{:>10} # ' ' +{:.<10} # '......' +{:0} # '' ``` * **Options can be generated dynamically: `f'{:{}[…]}'`.** * **Adding `'!r'` before the colon converts object to string by calling its [repr()](#class) method.** ### Strings ```python -{'abcde':10} # 'abcde ' -{'abcde':10.3} # 'abc ' -{'abcde':.3} # 'abc' -{'abcde'!r:10} # "'abcde' " +{'abcde':10} # 'abcde ' +{'abcde':10.3} # 'abc ' +{'abcde':.3} # 'abc' +{'abcde'!r:10} # "'abcde' " ``` ### Numbers ```python -{123456:10} # ' 123456' -{123456:10,} # ' 123,456' -{123456:10_} # ' 123_456' -{123456:+10} # ' +123456' -{123456:=+10} # '+ 123456' -{123456: } # ' 123456' -{-123456: } # '-123456' +{123456:10} # ' 123456' +{123456:10,} # ' 123,456' +{123456:10_} # ' 123_456' +{123456:+10} # ' +123456' +{123456:=+10} # '+ 123456' +{123456: } # ' 123456' +{-123456: } # '-123456' ``` ### 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%' +{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%' ``` #### Comparison of presentation types: @@ -476,9 +475,9 @@ Format ### Ints ```python -{90:c} # 'Z' -{90:b} # '1011010' -{90:X} # '5A' +{90:c} # 'Z' +{90:b} # '1011010' +{90:X} # '5A' ``` diff --git a/index.html b/index.html index 1ec7470..046c2da 100644 --- a/index.html +++ b/index.html @@ -365,9 +365,8 @@ to_exclusive = <range>.stop
  • As shown above, it restricts all special sequence matches to the first 128 characters and prevents '\s' from accepting '[\x1c-\x1f]' (the so-called separator characters).
  • Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).
  • -

    #Format

    <str> = f'{<el_1>}, {<el_2>}'            # Curly braces also accept expressions.
    -<str> = '{}, {}'.format(<el_1>, <el_2>)  # Or: '{0}, {1}'.format(<el_1>, <el_2>)
    -<str> = '%s, %s' % (<el_1>, <el_2>)      # Redundant and inferior C style formatting.
    +

    #Format

    <str> = f'{<el_1>}, {<el_2>}'        # Or: '{}, {}'.format(<el_1>, <el_2>)
    +<str> = '%s, %s' % (<el_1>, <el_2>)  # Redundant and inferior C style formatting.
     

    Attributes

    >>> Person = collections.namedtuple('Person', 'name height')
    @@ -378,36 +377,36 @@ to_exclusive   = <range>.stop
     '187'
     
    -

    General Options

    {<el>:<10}                               # '<el>      '
    -{<el>:^10}                               # '   <el>   '
    -{<el>:>10}                               # '      <el>'
    -{<el>:.<10}                              # '<el>......'
    -{<el>:0}                                 # '<el>'
    +

    General Options

    {<el>:<10}                           # '<el>      '
    +{<el>:^10}                           # '   <el>   '
    +{<el>:>10}                           # '      <el>'
    +{<el>:.<10}                          # '<el>......'
    +{<el>:0}                             # '<el>'
     
    • Options can be generated dynamically: f'{<el>:{<str/int>}[…]}'.
    • Adding '!r' before the colon converts object to string by calling its repr() method.
    -

    Strings

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

    Strings

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

    Numbers

    {123456:10}                              # '    123456'
    -{123456:10,}                             # '   123,456'
    -{123456:10_}                             # '   123_456'
    -{123456:+10}                             # '   +123456'
    -{123456:=+10}                            # '+   123456'
    -{123456: }                               # ' 123456'
    -{-123456: }                              # '-123456'
    +

    Numbers

    {123456:10}                          # '    123456'
    +{123456:10,}                         # '   123,456'
    +{123456:10_}                         # '   123_456'
    +{123456:+10}                         # '   +123456'
    +{123456:=+10}                        # '+   123456'
    +{123456: }                           # ' 123456'
    +{-123456: }                          # '-123456'
     
    -

    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%'
    +

    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%'
     

    Comparison of presentation types:

    ┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓
    @@ -439,9 +438,9 @@ to_exclusive   = <range>.stop
     
  • When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes '{6.5:.0f}' a '6' and '{7.5:.0f}' an '8'.
  • This rule only effects numbers that can be represented exactly by a float (.5, .25, …).
  • -

    Ints

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

    Ints

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

    #Numbers

    <int>      = int(<float/str/bool>)       # Or: math.floor(<float>)