I am using Python 2.4. I would like to print a string left justified but with an "offset". By that I mean, print a string with a set number of spaces before it.
Example:
Print string "Hello" in a space of width 20, left justified, but five spaces inserted before the string.
" Hello " #(The string has 5 spaces prior, and 10 space after)
print "Hello".ljust(20) #does not cut it.
I could use the following as a workaround:
print " ", "Hello".ljust(15)
Is there a better approach than printing a string of 5 spaces.
Thank you, Ahmed.
Not really.
>>> ' %-15s' % ('Hello',)
' Hello '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With