Python/string
string format
우리별3호
2019. 12. 26. 17:48
2 methods
1. % method
2. format() method
example)
In [7]: '%s, A, %s, and B' % ('first', 'second')
Out[7]: 'first, A, second, and B'
In [8]: '{}, A, {}, and B'.format('first', 'second')
Out[8]: 'first, A, second, and B'
In [20]: '{:>30,.2f}'.format(296999.2567)
Out[20]: ' 296,999.26'
In [21]: '{:>30,.2f}'.format(296999.2567)
Out[21]: ' 296,999.26'
In [22]: '{:>20,.2f}'.format(296999.2567)
Out[22]: ' 296,999.26'
In [23]: '{:->20,.2f}'.format(296999.2567)
Out[23]: '----------296,999.26'
In [24]: '{:_>20,.2f}'.format(296999.2567)
Out[24]: '__________296,999.26'
#