Planet Python
Follow
Rodrigo Girão Serrão: TIL #134 – = alignment in string formatting
Python's string formatting offers left, right, and center alignment. Numbers, however, have an additional alignment option denoted by the equals sign. Initially, this option might appear to have no effect on positive numbers. When the number is negative, the equals sign demonstrates its unique behavior by aligning the sign to the left and the digits to the right. This alignment is particularly useful when padding numbers with zeros. A shortcut for this zero-padding alignment is achieved by placing a zero directly before the specified width. This zero prefix modifies the default right alignment of numbers to behave like the equals sign alignment.