Do not show string format behavior

I see some unexpected behavior with the way str.format()bool types are handled when specifying alignment. Here is an example:

>>> '{}'.format(bool(1))
True

>>> '{:<}'.format(bool(1))
1

Please note - when I specified alignment, I formatswitched to displaying an integer instead True(I wanted to display bool, not an integer). I can force the desired result by moving the bool to the line as follows:

>>> '{:<}'.format(str(bool(1)))
True

My question is: can someone explain this edge case in str.format()?

+4
source share

All Articles