format
hoge = {'a': 'aa', 'b': 'bb'}
print('a is {a}\nb is {b}'.format(**hoge))
a is aa b is bb
### Left justified, center justified, right justified
```python
hoge = {'a': 'left', 'b': 'center', 'c': 'right'}
print('left : {a:<10}'.format(**hoge))
print('center: {b:^10}'.format(**hoge))
print('right : {c:>10}'.format(**hoge))
left : left center: center right : right
### Left justified, center justified, right justified (0 padded)
```python
hoge = {'a': 'left', 'b': 'center', 'c': 'right'}
print('left : {a:<010}'.format(**hoge))
print('center: {b:^010}'.format(**hoge))
print('right : {c:>010}'.format(**hoge))
left : left000000 center: 00center00 right : 00000right
### Left justified, center justified, right justified (character padding)
```python
hoge = {'a': 'left', 'b': 'center', 'c': 'right'}
print('left : {a:_<10}'.format(**hoge))
print('center: {b:_^10}'.format(**hoge))
print('right : {c:_>10}'.format(**hoge))
left : left______ center: center right : _____right
### Digit separator, decimal point
```python
print('{:,}'.format(1234.5678))
print('{:,.1f}'.format(1234.5678))
print('{:,.2f}'.format(1234.5678))
print('{:,.3f}'.format(1234.5678))
print('{:,.4f}'.format(1234.5678))
print('{:,.5f}'.format(1234.5678))
1,234.5678 1,234.6 1,234.57 1,234.568 1,234.5678 1,234.56780
## f character string
```python
a = 'aa'
b = 'bb'
print(f'a is {a}\nb is {b}')
a is aa b is bb
Recommended Posts