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

'Python > string' 카테고리의 다른 글

encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26

+ Recent posts