Reputation: 3652
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.
Upvotes: 3
Views: 4618