Python keep whitespace in a string -
how can keep white space in string?
i have string
piece = "**\n *\n *" ** * *
and want print in center, use function, doesn't keep white space
print '\n'.join('{0:^20}'.format(x, 'centered') x in piece.split('\n')) ** * *
i had output
* * ** insert move w piece before centring * *** * *** insert move w piece before centring ** * * ** * *
as can see second move right when print on center wrong
in python 3 getting :
>>> print ('\n'.join('{0:^20}'.format(x, 'centered') x in piece.split('\n')) ) ** * * >>>
Comments
Post a Comment