Formatting a string to be a constant length in Python -


lets have few string titles:

title0 = 'usa' title1 = 'canada' 

and want append list of '#' characters front , of these titles give them constant length like:

######## usa ######## ####### canada ###### 

with 1 space buffering start , end of text. can't symmetric number of symbols around word. there way built in python string formatting?

python's str.format() has few options should want. can read more them here. should give wanted.

title0 = '{:#^{width}}'.format(' usa ', width=19) title1 = '{:#^{width}}'.format(' canada ', width=19) 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

ruby - Nesting modules inside of a Rails eninge gem -

Eclipse formatter for java ending braces -