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

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -