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

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -