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 allow text alignment using three primary alignment specifiers:
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
f-strings in Python 3.6 are awesome
I feel like you should have given some examples. For us who are not familiar with f-strings this post doesn't really tell us much. More on reddit.com
🌐 r/Python
233
253
March 31, 2017
🌐
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
The procedure is as follows: • Placing between the quotation marks after the 'f' the text that you want displayed · • Enclosing the variables to be displayed within the text in curly braces · • Within those curly braces, placing a colon (:) after the variable · • Formatting the variable ...
🌐
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 - # Escape braces by doubling them print(f"{{curly braces}}") # {curly braces} # Backslashes in f-strings (use variables for Python 3.6-3.11 compatibility) newline = "\n" print(f"Line1{newline}Line2") # For complex expressions, use a variable path = "C:\\Users\\name" print(f"Path: {path}") # Path: C:\Users\name · name = "Alice" age = 30 city = "New York" # Using triple quotes message = f""" User Profile ------------ Name: {name} Age: {age} City: {city} """ print(message) # Concatenating f-strings message = ( f"Name: {name}\n" f"Age: {age}\n" f"City: {city}" ) print(message) # Create aligned tab
🌐
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 - Employ Formatting Options: Take ... appearance of variables within strings. For example, you can specify decimal places for numbers or alignment for strings. Prefer F-strings Over Older Methods: F-strings are the recommended way for string formatting in Python 3.6 and ...
🌐
ZetCode
zetcode.com › python › fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - F-strings allow you to justify strings to the left, right, or center within a given width. This is controlled by the >, <, and ^ characters after the colon. Justification is useful for aligning text in tables or output. ... #!/usr/bin/python words = ['sky', 'fork', 'small', 'cup', 'car', 'war'] ...
Find elsewhere
🌐
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.
🌐
datagy
datagy.io › home › python posts › python f-strings: everything you need to know!
Python f-strings: Everything you need to know! • datagy
December 20, 2022 - In order to format strings with alignment, you use any of <, >, ^ for alignment, followed by a digit of values of space reserved for the string. In particular: ... F-strings can also be used to apply number formatting directly to the values.
🌐
KDnuggets
kdnuggets.com › mastering-f-strings-in-python
Mastering f-strings in Python - KDnuggets
November 7, 2024 - For example, we will display the ... {percentage:.2%}") ... F-strings allow you to align text to the left, right, or center using <, >, and ^ respectively....
🌐
Medium
medium.com › @milansojitra1019 › unlocking-the-power-of-f-string-in-python-practical-examples-and-application-5c5e998f612b
Unlocking the Power of f-String in Python: Practical Examples and Application | by Milan Sojitra | Medium
June 1, 2024 - In the following sections, we will delve into the various features and capabilities of f-strings, supported by practical examples that highlight their versatility and efficiency in different use-cases. ... Output: Hello, Blue Heaven! Explanation : This basic example shows how to embed a variable directly within a string using f-strings.
🌐
Iditect
iditect.com › programming › python-example › string-alignment-in-python-f-string.html
String Alignment in Python f-string
Here's a brief overview of how ... # Outputs: "Pi is approximately 3.14 ." ... For simple alignment purposes, you'll mostly be using the fill, align, and width components....
🌐
DEV Community
dev.to › bybydev › advanced-string-formatting-with-f-strings-in-python-3a8b
Advanced string formatting with f-strings in Python - DEV Community
May 7, 2024 - price = 123.456789 # Format to ... ${price:.0f}" print(formatted_price_int) # Output: Price (rounded): $123 · You can use :<w, :>w, or :^w to align a string to the left, right, or center within a given width w, where w is an ...
🌐
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.
🌐
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
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
To specify a string as an f-string, simply put an f in front of the string literal, like this: ... To format values in an f-string, add placeholders {}, a placeholder can contain variables, operations, functions, and modifiers to format the value.
🌐
Built In
builtin.com › data-science › python-f-string
Guide to String Formatting in Python Using F-strings | Built In
more Python f-strings, introduced in version 3.6, allow cleaner string formatting by embedding variables directly. They support alignment, zero-padding, decimal precision, percentage display, comma separators and date formatting, making code ...
🌐
Real Python
realpython.com › python-formatted-output
A Guide to Modern Python String Formatting Tools – Real Python
February 1, 2025 - You create an f-string in Python by prepending a string literal with an f or F and using curly braces to include variables or expressions. You can use variables in Python’s .format() method by placing them inside curly braces and passing them ...
🌐
Mimo
mimo.org › glossary › python › formatted-strings
Python Formatted Strings / f-string formatting Guide
f-strings can include more than variables and values. They can include expressions, function calls, and even conditional logic: ... Python's so-called format mini-language provides advanced control over string formatting. Instead of just inserting values, the format mini-language allows you to specify field width, alignment, precision, and more.