Python print string centered -


i print centered string more 1 line

a = "*\n*\n**" 

i tried with

print '{0:^20}'.format(a, 'centered') 

but put in center first *, how can put string in center?

it center entire string:

>>> '{0:^20}'.format(a, 'centered') '       *\n*\n**       ' 

note puts 7 spaces before , after a. think expecting center content of each line, here how can that:

>>> print '\n'.join('{0:^20}'.format(x, 'centered') x in a.split('\n'))          *          *          ** 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -