How to right-align numeric data?

In python 2.6+ (and it’s the standard method in 3), the “preferred” method for string formatting is to use string.format() (the complete docs for which can be found here).
right justification can be done with

"a string {0:>5}".format(foo)

this will use 5 places, however

"a string {0:>{1}}".format(foo, width)

is also valid and will use the value width as passed to .format().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)