diff --git a/README.md b/README.md index ee3b223..98851a2 100644 --- a/README.md +++ b/README.md @@ -260,19 +260,38 @@ import re ### Format ```python -'{}'.format( [, , ...]) + = '{}, {}'.format(, ) +``` +#### Or: +```python + = f'{} {:<10} # ' ' +{:>10} # ' ' +{:^10} # ' ' +{:-^10} # '------' +{:^0} # '' ``` +#### Specific for strings: ```python -{:min_width} # ' ' -{:>min_width} # ' ' -{:^min_width} # ' ' -{:_____' -{:.max_width} # '' -{:max_width.min_width} # ' ' -{:max_width.no_of_decimalsf} # ' 3.14' +{'abcde':.3} # 'abc' +{'abcde':>10.3}' # ' abc' ``` +#### Specific for numbers: +```python +{1.23456:.3f} # '1.235' +{1.23456:>10.3f} # ' 1.235' +{123456:>10,} # ' 123,456' +{123456:>10_} # ' 123_456' +{3:08b} # '00000011' -> Binary with leading zeros. +```` + +#### Example: ```python >>> person = {'name': 'Jean-Luc', 'height': 187.1} >>> '{p[height]:.0f}'.format(p=person) @@ -291,12 +310,6 @@ import re * `'x'` - Hex * `'X'` - HEX -#### Binary, at least 10 spaces wide, filled with zeros: -```python ->>> f'{123:010b}' -'0001111011' -``` - ### Text Wrap ```python import textwrap