When using string formatting resulting string is longer than expected.
For example:
In [1]: "%s".ljust(7) % "123456"
Out[1]: '123456 '
Output string is not 7 characters long.
I’m interested in what is exactly happening ‘in the background’ to result in such behavior?
"%s"is being left adjusted to 7 places first – eg"%s ", and then you’re substituting the'123456'for the %s… hence the result you get…You could use:
Or specify appropriate width in the format string…