format
hoge = {'a': 'aa', 'b': 'bb'}
print('a is {a}\nb is {b}'.format(**hoge))
a is aa b is bb
### Linksbündig, mittigbündig, rechtsbündig
```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
### Linksbündig, mittigbündig, rechtsbündig (0 gepolstert)
```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
### Linksbündig, mittigbündig, rechtsbündig (mit Zeichen gefüllt)
```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
### Zifferntrennzeichen, Dezimalpunkt
```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 Zeichenkette
```python
a = 'aa'
b = 'bb'
print(f'a is {a}\nb is {b}')
a is aa b is bb
Recommended Posts