Specify it before the alignment character (> or <), without apostrophes.

contents = {"Introduction": 1, "Python Basics": 5, "Creating Your First Program": 12, "Operators and Variables": 29}
for chapt, page in contents.items():
    print(f"{chapt:.<30}{page:.>5}")

Outputs:

Introduction......................1
Python Basics.....................5
Creating Your First Program......12
Operators and Variables..........29

From the documentation

If a valid align value is specified, it can be preceded by a fill character that can be any character and defaults to a space if omitted. It is not possible to use a literal curly brace (“{” or “}”) as the fill character in a formatted string literal or when using the str.format() method. However, it is possible to insert a curly brace with a nested replacement field. This limitation doesn’t affect the format() function

Answer from pho on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › string-alignment-in-python-f-string
String Alignment in Python f-string - GeeksforGeeks
July 15, 2025 - Python’s f-strings make it easy ... text alignment using three primary alignment specifiers: < (Left Alignment): Aligns the text to the left within the specified width....
Discussions

f-string alignment
It works for me, mate. Maybe your computer is broken. >>> print(f"{'today':25}" + "xx") today xx >>> print(f"{'tomorrow':25}" + "xx") tomorrow xx >>> print(f"{'the day after tomorrow':25}" + "xx") the day after tomorrow xx Actually, looking at it a bit it's pretty clear that your browser is not using a monospace font. More on reddit.com
🌐 r/learnpython
6
1
April 29, 2023
python - Format output string, right alignment - Stack Overflow
I am processing a text file containing coordinates x, y, z 1 128 1298039 123388 0 2 .... every line is delimited into 3 items using words = line.split() After processing ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to left align a fixed width string? - Stack Overflow
With the new and popular f-strings in Python 3.6, here is how we left-align say a string with 16 padding length: More on stackoverflow.com
🌐 stackoverflow.com
How to align text centered on a character?
You can use the string formatting mini-language in an f-string or .format() string method. It's possible to left or right justify values in a given field width, along with many other neat manipulations. Here's a simple example showing how, try running it: # make up some dummy data: (label, value) data = (("longer name", 42), ("short", 3.14159), ("really really long", -5.1), ) label_width = 20 # must be at least width of longest label for (label, value) in data: print(f"{label:>{label_width}s}: {value}") Edit: grammar. More on reddit.com
🌐 r/learnpython
6
5
August 1, 2024
🌐
Bentley
cissandbox.bentley.edu › sandbox › wp-content › uploads › 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
A Guide to Formatting with f-strings in Python - CIS Sandbox
There are several ways to align variables in f-strings. The various alignment options are as ... Forces the expression within the curly braces to be left-aligned.
🌐
Medium
thetechplatform.medium.com › fstring-in-python-the-complete-guide-to-fstring-formatting-900676a768d5
Fstring in Python: The Complete Guide to Fstring Formatting | by The Tech Platform | Medium
February 12, 2024 - < indicates left-align, ^ is for center-align, and > is for right-align. The number represents the total width of the field. The result is neatly formatted text: ... You can easily control the precision of numbers displayed in your strings using ...
🌐
OneUptime
oneuptime.com › home › blog › how to use f-strings for string formatting in python
How to Use f-strings for String Formatting in Python
January 25, 2026 - text = "Python" # Minimum width with alignment print(f"|{text:10}|") # |Python | (left, default for strings) print(f"|{text:<10}|") # |Python | (left) print(f"|{text:>10}|") # | Python| (right) print(f"|{text:^10}|") # | Python | (center) # Custom fill character print(f"|{text:*<10}|") # |Python****| print(f"|{text:*>10}|") # |****Python| print(f"|{text:*^10}|") # |**Python**| # Numbers are right-aligned by default num = 42 print(f"|{num:10}|") # | 42| print(f"|{num:<10}|") # |42 |
🌐
Note.nkmk.me
note.nkmk.me › home › python
Right-justify, Center, Left-justify Strings and Numbers in Python | note.nkmk.me
May 18, 2023 - Format strings and numbers with format() in Python · To right-justify, center, or left-justify, use [CHARACTER][DIRECTION][STRING_LENGTH] as the format string.
🌐
Medium
medium.com › @NirantK › best-of-python3-6-f-strings-41f9154983e
Best of Python3.6 f-strings. f-strings (formatted strings) for those… | by Nirant Kasliwal | Medium
April 16, 2018 - This is much easier with Python f-strings using the colon ‘:’ operator, followed by a an alignment operator and field width value. There are atleast 3 alignment operator: < for left aligned, > for right aligned, and ^ for center aligned.
Find elsewhere
🌐
KDnuggets
kdnuggets.com › mastering-f-strings-in-python
Mastering f-strings in Python - KDnuggets
November 7, 2024 - F-strings allow you to align text to the left, right, or center using <, >, and ^ respectively.
🌐
TutorialsPoint
tutorialspoint.com › how-to-align-text-strings-using-python
How to Align Text Strings using Python?
Python provides multiple ways to align text: f-strings with alignment specifiers and built-in string methods like ljust(), rjust(), and center(). Python's text alignment feature helps create well-formatted output. When data varies in length, proper alignment makes output more readable and professional-looking. You can specify left, right, or center alignment with a reserved width for consistent formatting.
🌐
Python
bugs.python.org › issue36912
Issue 36912: Can't left-align strings using f-strings or format() - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/81093
🌐
Medium
medium.com › @pivajr › pythonic-tips-how-to-align-strings-to-the-left-right-and-center-in-python-557db734cce6
Pythonic Tips: How to Align Strings to the Left, Right, and Center in Python | by Dilermando Piva Junior | Medium
May 22, 2025 - Here, ljust(20) ensures the product name is left-aligned within a 20-character column, while rjust(20) pushes monetary values to the right, creating a table-like illusion in terminal interfaces. The center() method is perfect for headers and visual dividers. Introduced in Python 3.6, f-strings bring poetic elegance to text formatting.
🌐
Towards Data Science
towardsdatascience.com › home › programming › formatting strings and numbers in python
Formatting strings and numbers in python | Towards Data Science
June 27, 2021 - You can use the :>, :< or :^ option in the f-format to left align, right align or center align the text that you want to format. ... After formatting the alignment of output text ...
🌐
LernerPython
lernerpython.com › home › lernerpython blog › python f-string format specifiers: aligning and padding text
Python f-string format specifiers: Aligning and padding text - LernerPython
April 29, 2026 - Use in f-string format specifiers, with a width integer and a custom fill character, to left-align, center or right-align and pad text.
Top answer
1 of 8
337

Try this approach using the newer str.format syntax. This uses a width of 12, space padded, right aligned.

line_new = '{:>12}  {:>12}  {:>12}'.format(words[0], words[1], words[2])

Example with the interpreter:

>>> line = "123 456 789"
>>> words = line.split(' ')
>>> line_new = '{:>12}  {:>12}  {:>12}'.format(words[0], words[1], words[2])
>>> print(line_new)
         123           456           789

And here's how to do it using the old % syntax (useful for older versions of Python that don't support str.format):

line_new = '%12s  %12s  %12s' % (words[0], words[1], words[2])
2 of 8
90

Here is another way how you can format using 'f-string' format:

print(
    f"{'Trades:':<15}{cnt:>10}",
    f"{'Wins:':<15}{wins:>10}",
    f"{'Losses:':<15}{losses:>10}",
    f"{'Breakeven:':<15}{evens:>10}",
    f"{'Win/Loss Ratio:':<15}{win_r:>10}",
    f"{'Mean Win:':<15}{mean_w:>10}",
    f"{'Mean Loss:':<15}{mean_l:>10}",
    f"{'Mean:':<15}{mean_trd:>10}",
    f"{'Std Dev:':<15}{sd:>10}",
    f"{'Max Loss:':<15}{max_l:>10}",
    f"{'Max Win:':<15}{max_w:>10}",
    f"{'Sharpe Ratio:':<15}{sharpe_r:>10}",
    sep="\n"
)

This will provide the following output:

Trades:              2304
Wins:                1232
Losses:              1035
Breakeven:             37
Win/Loss Ratio:      1.19
Mean Win:           0.381
Mean Loss:         -0.395
Mean:               0.026
Std Dev:             0.56
Max Loss:          -3.406
Max Win:             4.09
Sharpe Ratio:      0.7395

What you are doing here is you are saying that the first column is 15 chars long and it's left-justified and the second column (values) is 10 chars long and it's right-justified.

If you joining items from the list and you want to format space between items you can use `` and regular formatting techniques.

This example separates each number by 3 spaces. The key here is f"{'':>3}"

print(f"{'':>3}".join(str(i) for i in range(1, 11)))

output:

1   2   3   4   5   6   7   8   9   10
🌐
YouTube
youtube.com › shorts › elzAmldcR_g
How To Align Text Using F-Strings - YouTube
In this python tutorial, I show you how to align text using f-strings in python! Let's get coding!======== Ask Case Digital ========If you have a question yo...
Published: December 3, 2024
🌐
Scaler
scaler.com › home › topics › python › string formatting in python
String Formatting in Python - Scaler Topics
June 11, 2024 - We can also perform different ... we use the same syntax we used for the alignment of numbers. To left-align a string, we use the “:<n” symbol inside the placeholder....
🌐
LabEx
labex.io › tutorials › python-how-to-manipulate-python-string-alignment-419448
How to manipulate Python string alignment | LabEx
Python provides built-in methods for string alignment: ... At LabEx, we recommend practicing string alignment techniques to enhance your Python text processing skills. text = "Hello" left_aligned = text.ljust(10) print(f"'{left_aligned}'") ## Output: 'Hello '
🌐
ZetCode
zetcode.com › python › fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - The syntax is {value:fill_char align width}, where fill_char is any single character, align is one of ^ (center), > (right), or < (left), and width is the total field width. This gives you precise control over how your output appears. $ python main.py ************TITLE************ ...