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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_print.asp
Python print() Function
Python Examples Python Compiler ... Interview Q&A Python Training ... The print() function prints the specified message to the screen, or other standard output device....
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-print.html
print() and Standard Out
The Python print() function takes in any number of parameters, and prints them out on one line of text. The items are each converted to text form, separated by spaces, and there is a single '\n' at the end (the "newline" char). When called with zero parameters, print() just prints the '\n' ...
Discussions

So how does Print function work in Python?
print just writes to sys.stdout by default. def print(*args, sep=" ", end="\n", file=sys.stdout): text = sep.join(str(arg) for arg in args) file.write(text) file.write(end) That'd pretty much do the same thing. Some functions and classes in CPython (the Python you get from python.org) are implemented in a programming language called C which is what CPython is written in. That means some stuff in Python will not be implemented in Python itself. More on reddit.com
๐ŸŒ r/learnprogramming
5
10
October 11, 2022
python - What is print(f"...") - Stack Overflow
For those who are new to python: The repr() function returns a printable representational string of the given object. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Printing a function in Python - Stack Overflow
I'm just starting to learn Python, and I'm currently reading a book that is teaching me, and in the book a function just like the one I have made below prints the actual text that is defined in the... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python - print function output - Stack Overflow
def cent_to_fahr(cent): print (cent / 5.0 * 9 + 32) print (cent_to_fahr(20)) The output is this : 68.0 None Why this output has None? I didn't get this result when I use just cent_to_fahr(20... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ builtins โ€บ functions.html
Built-in functions โ€” Python 3.15.0 documentation
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ print-function
Explore Python's print() function, master output customization
The print() function is useful in command line applications and for debugging purposes. You can use print() within try-except blocks to output error messages. In Python, printing error messages can help diagnose and fix errors during development.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ so how does print function work in python?
r/learnprogramming on Reddit: So how does Print function work in Python?
October 11, 2022 -

So I am a beginner who was learning python and the first thing I learnt was printing strings. Then later on I learnt about functions and it's only now I realised that print itself is a function. Like when we say print ('hello world') we are basically calling an already existing function and not doing anything new. I didn't realise it till now. But the question I got is what does this original print function contain? How does it work? Is it possible for me to built it from scratch by myself?

Top answer
1 of 3
11
print just writes to sys.stdout by default. def print(*args, sep=" ", end="\n", file=sys.stdout): text = sep.join(str(arg) for arg in args) file.write(text) file.write(end) That'd pretty much do the same thing. Some functions and classes in CPython (the Python you get from python.org) are implemented in a programming language called C which is what CPython is written in. That means some stuff in Python will not be implemented in Python itself.
2 of 3
9
I didn't realise it till now. But the question I got is what does this original print function contain? How does it work? Is it possible for me to built it from scratch by myself? Someone had to build Python from scratch by themselves, so yes, it's possible. You might not be able to do it in pure Python, though. If you look inside the print() function, and follow the code, eventually you'll get to a point where you need to start looking at the Python interpreter, which is likely written in C. If you follow that C code, you'll eventually get to a place where the C code makes what is called a "system call". A system call looks like a normal C function call, but the function that is being called is in the operating system kernel. On modern computers, the operating system is responsible for coordinating how different programs interact on the system. Any time a program wants to output data, it has to go through the operating system. This includes writing to files, sending data across the network, sending data to other process, and sending data to the screen. You don't need to have a deep understanding of how the operating system does this, just what system calls exist and how to use them. On Linux, the specific system call that is ultimately responsible for sending your string to the operating system is called write(). Different operating systems will have a different set of system calls, and I'm not sure what system call gets used on other operating systems.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ inputoutput.html
7. Input and output โ€” Python 3.15.0 documentation
>>> animals = 'eels' >>> print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels.
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ sentdex
Python 3 Tutorial: Print Function and Strings - YouTube
The print function in Python is a function that outputs to your console window whatever you say you want to print out. At first blush, it might appear that t...
Published: January 22, 2014
Views: 476K
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-print-function
Python print() function - GeeksforGeeks
The print() function in Python displays the given values as output on the screen. It can print one or multiple objects and allows customizing separators, endings, output streams and buffer behavior.
Published: March 7, 2026
๐ŸŒ
Real Python
realpython.com โ€บ python-print
Your Guide to the Python print() Function โ€“ Real Python
July 3, 2026 - Without parentheses, youโ€™d obtain a reference to the underlying function object: ... 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().
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
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ print-features
The power of Python's print function - Python Morsels
August 3, 2026 - Python's print function doesn't just accept more than one argument, it accepts any number of positional arguments.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python's powerful print() function - YouTube
Python's print() function includes abilities that are easily overlooked, even by long-time Pythonistas.Article at https://pym.dev/the-power-of-print/More #Py...
Published: September 3, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-output-using-print-function
Python - Print Output using print() function - GeeksforGeeks
Python print() function prints the message to the screen or any other standard output device.
Published: July 11, 2025
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-print-function
A Complete Guide to the Python print() Function | LearnPython.com
January 25, 2022 - Try printing the same list without the star and see what you get. Also, try printing the sequence given by the built-in function range() with and without the star. Weโ€™ll see some more examples with starred expressions in the next section. The second argument of the Python print() function defines the separator.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-print-function
Python Print() Function: How to use Print Statement with Examples | DataCamp
February 28, 2020 - Having said that, let's check the type/class of the print() function. ... It returns builtin_function_or_method, which means it is a predefined or a builtin Python Function.
๐ŸŒ
Medium
allwin-raju.medium.com โ€บ everything-you-need-to-know-about-pythons-print-function-1ae9692b71f3
Everything You Need to Know About Pythonโ€™s print() Function | by Allwin Raju | Medium
January 2, 2025 - The print function in Python is one of the most commonly used built-in functions. It outputs text or other data to the console or a specified file-like object.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Where can I find a comprehensive list of ALL print() arguments? - Python Help - Discussions on Python.org
September 16, 2022 - Where is the official definition ... function using sys.stdout. There seems to be no official definition of the print function, and only a general description about its capabilities on doc.python.org....
๐ŸŒ
Medium
cycoderx.medium.com โ€บ the-secrets-of-the-print-function-91d9fe5eda0e
The secrets of the Print() Function! | by CyCoderX | Medium
August 8, 2024 - The print() function in Python is a versatile tool for displaying output. By leveraging its parameters such as sep, end, file and flush, you can control the formatting, destination and timing of your printed output.