Old '%s
%s'
%
('one',
'two')
New '{} {}'.format('one', 'two')
Old '%d %d' % (1, 2)
New '{} {}'.format(1, 2)
New
'{1}
{0}'.format('one',
'two')
Output
two
one
Padding
and aligning strings
Align
right:
Old '%10s' % ('test',)
New '{:>10}'.format('test')
Output
test
Align left:Old '%-10s' % ('test',)
New '{:10}'.format('test')
Output test
And
also center align values:
New '{:^10}'.format('test')
Output
test
Padding
numbers
Ol
d
'
%4d
'
%
(
42
,)
No comments:
Post a Comment