How do I use the string format
function to pre-pend a specified number of spaces to a string? Everything I search (e.g. this post and this post) tells me to use something like
"{:>15}".format("Hello")
But that will give me 10 spaces in front. What if I always want to put 4 spaces in front, keeping things left-aligned, when the input strings are of variable length? For example:
Hello
Goodbye
I thought of doing
"{:4}{}".format("", "Hello")
Which does work, but then I have to pass in this bogus empty string. Is there a cleaner way to achieve this?