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

Popular posts from this blog

SPSS keyboard combination alters encoding -

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

CSS3 Transition to highlight new elements created in JQuery -