Skip to content Skip to sidebar Skip to footer

Aligning Strings In Python

I searched for creating aligned strings in Python and found some relevant stuff, but didn't work for me. Here's one example: for line in [[1, 128, 1298039], [123388, 0, 2]]: pr

Solution 1:

You have configured your IDLE shell to use a proportional font, one that uses different widths for different characters. Notice how the () pair takes almost the same amount of horizontal space as the > character above it.

Your code is otherwise entirely correct; with a fixed-width font the numbers will line up correctly.

Switch to using a fixed width font instead. Courier is a good default choice, but Windows has various other fonts installed that are proportional, including Consolas.

Configure the font in the Options -> Configure IDLE menu. Pick a different font from the Font Face list. The sample characters in the panel below should line up (except for the second line k at the end, it should stick out).


Post a Comment for "Aligning Strings In Python"