I'd like to allign a string to the right but have its beginning be truncated instead of its end.
I tried this:
my_str = '01234567890'
print "{0:>4.4}".format(my_str)
Output:
'0123'
Desidered Output:
'7890'
Is there a way to do this with format
or do I have to cut the string before feeding it?
You can use the reverse of the string as input and reverse again the output.
Output:
Note that a more complex way is described here (StackOverflow question 37974565), which offers a solution if the input string may not be changed (substring, reverse).