This question already has an answer here:
I'm seeing some unexpected behaviour with how str.format() handles bool types when specifying alignment. Here's the example:
>>> '{}'.format(bool(1))
True
>>> '{:<}'.format(bool(1))
1
Notice -- when I specified alignment, format switched to displaying an integer instead of True (I wanted to display the bool, not an integer). I can force the desired output by casting the bool to string thusly:
>>> '{:<}'.format(str(bool(1)))
True
My question is -- can anyone explain this edge case in str.format() ?
Aucun commentaire:
Enregistrer un commentaire