[Tutor] Making table

Kent Johnson kent37 at tds.net
Mon Mar 19 16:53:06 CET 2007


Dave Kuhlman wrote:
> Try ljust and rjust.  They are string functions/methods and are
> described here: http://docs.python.org/lib/string-methods.html
> 
> Something like the following might work for you:
> 
>     In [1]: value = 3.45678
>     In [2]: ("%0.3f" % value).rjust(10)
>     Out[2]: '     3.457'

Most string formatting conversions allow you to specify a width 
directly. For example,
In [61]: value = 3.45678
In [63]: "%10.3f" % value
Out[63]: '     3.457'

Kent


More information about the Tutor mailing list