The f means Formatted string literals and it's new in Python 3.6.


A formatted string literal or f-string is a string literal that is prefixed with f or F. These strings may contain replacement fields, which are expressions delimited by curly braces {}. While other string literals always have a constant value, formatted strings are really expressions evaluated at run time.


Some examples of formatted string literals:

>>> name = "Fred"
>>> f"He said his name is {name}."
"He said his name is Fred."

>>> name = "Fred"
>>> f"He said his name is {name!r}."
"He said his name is Fred."

>>> f"He said his name is {repr(name)}." # repr() is equivalent to !r
"He said his name is Fred."

>>> width = 10
>>> precision = 4
>>> value = decimal.Decimal("12.34567")
>>> f"result: {value:{width}.{precision}}" # nested fields
result: 12.35

>>> today = datetime(year=2023, month=1, day=27)
>>> f"{today:%B %d, %Y}" # using date format specifier
January 27, 2023

>>> number = 1024
>>> f"{number:#0x}" # using integer format specifier
0x400
Answer from Pedro Lobito on Stack Overflow
Top answer
1 of 7
151

The f means Formatted string literals and it's new in Python 3.6.


A formatted string literal or f-string is a string literal that is prefixed with f or F. These strings may contain replacement fields, which are expressions delimited by curly braces {}. While other string literals always have a constant value, formatted strings are really expressions evaluated at run time.


Some examples of formatted string literals:

>>> name = "Fred"
>>> f"He said his name is {name}."
"He said his name is Fred."

>>> name = "Fred"
>>> f"He said his name is {name!r}."
"He said his name is Fred."

>>> f"He said his name is {repr(name)}." # repr() is equivalent to !r
"He said his name is Fred."

>>> width = 10
>>> precision = 4
>>> value = decimal.Decimal("12.34567")
>>> f"result: {value:{width}.{precision}}" # nested fields
result: 12.35

>>> today = datetime(year=2023, month=1, day=27)
>>> f"{today:%B %d, %Y}" # using date format specifier
January 27, 2023

>>> number = 1024
>>> f"{number:#0x}" # using integer format specifier
0x400
2 of 7
63

In Python 3.6, the f-string, formatted string literal, was introduced(PEP 498). In short, it is a way to format your string that is more readable and fast.

Example:

agent_name = 'James Bond'
kill_count = 9


# old ways
print("%s has killed %d enemies" % (agent_name,kill_count))

print('{} has killed {} enemies'.format(agent_name,kill_count))
print('{name} has killed {kill} enemies'.format(name=agent_name,kill=kill_count))
    

# f-strings way
print(f'{agent_name} has killed {kill_count} enemies')

The f or F in front of strings tell Python to look at the values , expressions or instance inside {} and substitute them with the variables values or results if exists. The best thing about f-formatting is that you can do cool stuff in {}, e.g. {kill_count * 100}.

You can use it to debug using print e.g.

print(f'the {agent_name=}.')
# the agent_name='James Bond'

Formatting, such as zero-padding, float and percentage rounding is made easier:

print(f'{agent_name} shoot with {9/11 : .2f} or {9/11: .1%} accuracy')
# James Bond shoot with  0.82 or  81.8% accuracy 

Even cooler is the ability to nest and format. Example date


from datetime import datetime

lookup = {
    '1': 'st',
    '21': 'st',
    '31': 'st',
    '2': 'nd',
    '22': 'nd',
    '3': 'rd',
    '23': 'rd'
}

dato = datetime.now()

print(f"{dato: %B %-d{lookup.get(f'{dato:%-d}', 'th')} %Y}")

# April 23rd 2022

Pretty formatting is also easier

tax = 1234

print(f'{tax:,}') # separate 1k \w comma
# 1,234

print(f'{tax:,.2f}') # all two decimals 
# 1,234.00

print(f'{tax:~>8}') # pad left with ~ to fill eight characters or < other direction
# ~~~~1234

print(f'{tax:~^20}') # centre and pad
# ~~~~~~~~1234~~~~~~~~

The __format__ allows you to funk with this feature. Example


class Money:
    
    def __init__(self, value, currency='€'):
        self.currency = currency
        self.value = value
        
    def __repr__(self):
        return f'Money(value={self.value}, currency={self.currency})'
        
    def __format__(self, *_):
        
        return f"{self.currency}{float(self.value):.2f}"
        
        
tax = 12.3446
money = Money(tax, currency='$')

print(f'{money}')
# $12.34

print(money)
# Money(value=12.3446, currency=$)

There is much more. Readings:

  • PEP 498 Literal String Interpolation
  • Python String Formatting
🌐
GeeksforGeeks
geeksforgeeks.org › python › formatted-string-literals-f-strings-python
f-strings in Python - GeeksforGeeks
May 16, 2026 - Example 3: This example evaluates an expression directly inside an f-string. ... Physics = 78 Chemistry = 56 Biology = 85 print(f"Alex got total marks {Physics + Chemistry + Biology} out of 300")
Discussions

What does the "f" stand for in an f string? Why not some other letter?
🌐 r/learnpython
90
198
November 27, 2021
What's the purpose of f'strings?
F strings are just a nice way to insert variables into a template string. Yes, there are other ways - but f strings are usually the best. What way would you use instead? More on reddit.com
🌐 r/learnpython
91
157
January 28, 2024
What's the f in the print statement do?
Here’s a simple code: for x in range(100): print(f"{x} bottles of beer on the wall!") In the print statement there’s an f outside the quoted expression. What does it do? What does it mean? I am just starti ng with Python… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
February 16, 2023
Help with undefined variable error
Your function needs to return newstr, and in main() you need to assign that value to a variable then print that More on reddit.com
🌐 r/learnpython
12
4
November 9, 2019
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and output — Python 3.15.0 documentation
So far we’ve encountered two ways of writing values: expression statements and the print() function. (A third way is using the write() method of file objects; the standard output file can be referenced as sys.stdout.
🌐
Medium
medium.com › gustavorsantos › f-string-the-easiest-way-to-print-in-python-82f9aca01855
F-string: the easiest way to print() in Python - gustavorsantos - Medium
December 8, 2022 - F-string: the easiest way to print() in Python Learn how to use the f-strings. The easiest way to print a message in Python is using f-strings. Present since version 3.6, the “f-string” came to …
🌐
EyeHunts
tutorial.eyehunts.com › home › print(f python) | python f print – example code
Python f print - Example code - Tutorial - By EyeHunts
April 28, 2022 - Print(f Python): The f means Formatted string literals and it’s new in Python 3.6.
🌐
YouTube
youtube.com › watch
Print() and F-Strings in Python Explained ✔️ - YouTube
Hi everyone, in this video, I'm going to show you how to use f strings along with the print statement in Python. F-strings, also known as formatted string li...
Published: March 27, 2024
🌐
Entri
entri.app › home › python print function
Python Print Function
2 weeks ago - python foundations · Python Input Function Python Print Function Introduction to Python · Last Updated: 30 Sep, 2026 · print() is a built-in function that writes values to the standard output (your screen or terminal). Its full signature is: print(*objects, sep=” “, end=”\n”, ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
price = 49 txt = f"It is very {'Expensive' if price>50 else 'Cheap'}" print(txt) Try it Yourself » ... The function does not have to be a built-in Python method, you can create your own functions and use them:
🌐
LabEx
labex.io › tutorials › python-formatting-python-print-statements-91
Python Basics | Print() Function | Format Specifiers | f-Strings | LabEx
However, they are not available in older versions of Python, so if you need to support those versions, you will need to use the % operator or another method for formatting strings. In this lab, we learned how to use the print() function to display output to the console, and how to format that output using the f-strings, and format specifiers.
🌐
Thecodeforge
thecodeforge.io › home › python › python print() function: syntax, formatting and real examples
Python print() Function: Syntax, Formatting and Real Examples | TheCodeForge
April 20, 2026 - Reach for f-strings over concatenation or .format() every time — they're faster, they fail at parse time instead of runtime, and format specifiers like :.2f and :>10 replace entire formatting libraries for simple output. ✦ Plain-English analogy ✦ Real code with output ✦ Interview questions ... Think of print() as a PA system announcement in a big office building. Your Python program is doing work quietly in a back room, and print() is the moment someone walks to the microphone and broadcasts what's happening to everyone in the building.
🌐
CodeRivers
coderivers.org › blog › print-f-python
Mastering print(f) in Python: A Comprehensive Guide - CodeRivers
August 8, 2026 - In the world of Python programming, ... format and print strings in Python. Introduced in Python 3.6, f-strings provide a concise, readable, and efficient way to embed expressions inside string literals....
🌐
Real Python
realpython.com › python-f-strings
Python's F-String for String Interpolation and Formatting – Real Python
November 30, 2024 - Note how your f-string in the call to print() takes advantage of format specifiers to conveniently format the code’s output. If you run the script from your command line, then you’ll get an output similar to the following. Of course, the numbers will be different for you: ... This output shows that f-strings are a bit faster than the % operator and the .format() method, which is the slowest tool because of all the required function calls.
🌐
Tutorials
zframez.com › tutorials › chapter 4: mastering the print function in python
Chapter 4: Mastering the Print Function in Python - Tutorials
October 16, 2024 - Okay… now start with these following simple print statements and try to understand how Python displays the output. print ( 10 ) # Output : 10 print ( "Hello" ) # Output : Hello print ( 10, 20 ) # Output : 10 20 print ( "Hello world" ) # Output : Hello world print ( "Hello", 10 ) # Output : Hello 10 · Note that parentheses, quotes and commas are part of the syntax and are not displayed in the output. ... You can print variables using the “print” function.
🌐
Python Morsels
pythonmorsels.com › print-features
The power of Python's print function - Python Morsels
August 3, 2026 - Python's print function can accept more than one argument: >>> count = 4 >>> print("There are", count) There are 4 · Python's f-strings pair very nicely with the print function.
🌐
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
a type of report that is often produced in a typical Python program. Notice the use of the dollar · sign ($) just before the variables that are to be displayed as prices. APPLES = .50 · BREAD = 1.50 · CHEESE = 2.25 · numApples = 3 · numBread = 10 · numCheese = 6 · prcApples = numApples * APPLES · prcBread = numBread* BREAD · prcCheese = numCheese * CHEESE · strApples = 'Apples' strBread = 'Rye Bread' strCheese = 'Cheese' total = prcBread + prcCheese + prcApples · print(f'{"My Grocery List":^30s}') print(f'{"="*30}') print(f'{strApples:10s}{numApples:10d}\t${prcApples:>5.2f}') print(f'{strBread:10s}{numBread:10d}\t${prcBread:>5.2f}') print(f'{strCheese:10s}{numCheese:10d}\t${prcCheese:>5.2f}') print(f'{"Total:":>20s}\t${total:>5.2f}') The output of this code snippet is: My Grocery List ·
🌐
w3resource
w3resource.com › python › python-print-statement.php
Python print() function
The print() function is a fundamental part of Python that allows for easy console output. The function has replaced the older print statement in Python 3, providing more versatility with keyword arguments.
🌐
Real Python
realpython.com › python-print
Your Guide to the Python print() Function – Real Python
July 3, 2026 - The code snippet above runs within an interactive Python REPL, as indicated by the prompt (>>>). Because the REPL executes each line of Python code immediately, you see a blank line right after calling print(). On the other hand, when you skip the trailing parentheses, you get to see a string representation of the print() function itself. As you just saw, calling print() without arguments results in a blank line, which is a line comprised solely of the newline character. Don’t confuse this with an empty string, which doesn’t contain any characters at all, not even the newline! You can use Python’s string literals to visualize these two: ... The first string literal is exactly one character long, whereas the second one has no content—it’s empty.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
What's the f in the print statement do? - Curriculum Help - The freeCodeCamp Forum
February 16, 2023 - Here’s a simple code: for x in range(100): print(f"{x} bottles of beer on the wall!") In the print statement there’s an f outside the quoted expression. What does it do? What does it mean? I am just starti ng …