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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_center.asp
Python String center() Method
Python Overview Python Built-in ... Interview Q&A Python Training ... The center() method will center align the string, using a specified character (space is default) as the fill character....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-alignment-in-python-f-string
String Alignment in Python f-string - GeeksforGeeks
July 15, 2025 - Pythonโ€™s f-strings allow text ... Aligns the text to the right within the specified width. ^ (Center Alignment): Centers the text within the specified width....
Discussions

Help centering multiple f strings?
You could use len() to figure out the length of the string you want to print, and calculate the necessary "padding" based on that. For example, if you want a string to be centered in a field that is forty spaces wide, field_size = 40 mystring_length = len(mystring) leading_spaces = (field_size - mystring_length) // 2 trailing_spaces = field_size - mystring_length - leading_spaces print(f"{' '*leading_spaces}{mystring}{' '*trailing_spaces}") More on reddit.com
๐ŸŒ r/learnpython
16
1
October 16, 2023
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
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-align-text-strings-using-python
How to Align Text Strings using Python?
# Right align with 30 character width text = "Right Aligned String!" print(f"{text:>30}") print(f"{'Hello':>20}World") ... # Center align with 30 character width text = "Center Aligned String!" print(f"{text:^30}") print(f"{'Hello':^20}")
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ help centering multiple f strings?
r/learnpython on Reddit: Help centering multiple f strings?
October 16, 2023 -

I am trying to centre the following ( didn't want to include the whole code as its 166 lines long)

for years in range (1,5):
Payments = years * 12
FinFee = (39.99) * years
TotPrice = TotalSalesPrice + FinFee
MonPay = TotPrice / 12

FinFeeDSP = "${:,.2f}".format(FinFee)
TotPriceDSP = "${:,.2f}".format(TotPrice)
MonPayDSP = "${:,.2f}".format(MonPay)
print(f" {years:^2d} {Payments:^9d} {FinFeeDSP:^9s} {TotalSalesPriceDSP:^9s} {MonPayDSP:^9s}")
print(f"------------------------------------------------------------------------")
CurDate = datetime.datetime.now()
CurDatePlus30 = CurDate + datetime.timedelta(days = 30)
print(f"Invoice date: {CurDate.strftime('%d-%b-%y').upper()} First payment date: {CurDatePlus30.strftime('%d-%b-%y').upper()}")
print()
print()

Maybe centre isn't the right word, but I'm trying to get the f strings with equal padding/space on each side. Right now it lines up with the printed f-strings above it and I need it more in the middle.

It currently looks like this: https://imgur.com/a/hpBBcLN

I need the table on the bottom entered or indented so there is equal space on both sides

๐ŸŒ
Sling Academy
slingacademy.com โ€บ article โ€บ python-how-to-algin-a-string
Python: How to Algin a String (Left, Right, and Center) - Sling Academy
If the width is smaller than the length of the original string, the original string is returned as is. If fillchar is provided, it is used as the fill character instead of spaces. To align a string using f-strings in Python, you can make use of format specifiers and alignment options.
๐ŸŒ
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 - Here are the common symbols for string alignment and padding in Fstring: <: Left-align the string within the specified width. ^: Center-align the string within the specified width.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-string-center-method
Python String center() Method - Learn By Example
April 20, 2020 - By default the string is padded with whitespace (ASCII space). You can modify that by specifying a fill character. # center() with '*' as a fill character S = 'Centered' x = S.center(14, '*') print(x) # Prints ***Centered*** You can achieve the same result by using format() method. # Align text center with format() S = 'Centered' x = '{:*^14}'.format(S) print(x) # Prints ***Centered***
๐ŸŒ
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 |
๐ŸŒ
W3schools-fa
w3schools-fa.ir โ€บ python โ€บ ref_string_center.html
Python String center() Method
Python Overview Python Built-in ... Python Set Methods Python File Methods Python Keywords ... The center() method will center align the string, using a specified character (space is default) as the fill character....
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Right-justify, Center, Left-justify Strings and Numbers in Python | note.nkmk.me
May 18, 2023 - i = 123 print(type(i)) # <class 'int'> print(str(i).rjust(8, '*')) # *****123 print(str(i).center(8, '*')) # **123*** print(str(i).ljust(8, '*')) # 123***** ... Both the built-in format() function and the format() method of str allow various formatting options. See the following article for more information. Format strings and numbers with format() in Python
๐ŸŒ
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.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-center-strings-dynamically-419439
How to center strings dynamically | LabEx
## Simple string centering demonstration text = "LabEx Python Tutorial" centered_text = text.center(30) print(centered_text) This example demonstrates how Python's built-in .center() method simplifies text alignment, making it accessible for ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ center
Python String center() (With Examples)
# returns the centered padded string of length 24 new_string = sentence.center(24, '*') print(new_string) # Output: ***Python is awesome**** ... Here, str is a string. ... Note: If fillchar is not provided, whitespace is taken as the default argument.
๐ŸŒ
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. This is the ... Forces the expression within the curly braces to be right-aligned. This is the ... Forces the expression within the curly braces to be centered...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_string_formatting.asp
Python String Formatting
Before Python 3.6 we had to use the format() method. ... F-string allows you to format selected parts of a string.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-center-strings-with-padding-in-python-419440
How to center strings with padding in Python | LabEx
This process helps in formatting text, aligning output, and creating consistent visual representations. In Python, there are several methods to pad strings: ... ## Basic string padding demonstration text = "Python" ## Left padding with spaces left_padded = text.ljust(10) print(f"Left padded: '{left_padded}'") ## Right padding with spaces right_padded = text.rjust(10) print(f"Right padded: '{right_padded}'") ## Center padding with spaces center_padded = text.center(10) print(f"Center padded: '{center_padded}'")
๐ŸŒ
py4u
py4u.org โ€บ blog โ€บ python-string-formatter-align-center
Python String Formatting: How to Center Align Text Within 24 Spaces โ€“ Quick Methods & Math Explained
Pythonโ€™s built-in str.center(width, fillchar=' ') method is the most straightforward way to center text. It takes two arguments: width: Total length of the resulting string (24 in our case).
๐ŸŒ
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.