I'm afraid that it will be deprecated during the next Python versions

Don't be, str.format does not appear (nor has a reason) to be leaving any time soon, the PEP that introduced fprefixed-strings even states in its Abstract:

This PEP does not propose to remove or deprecate any of the existing string formatting mechanisms.

Formatted strings were introduced to address some of the shortcomings other methods for formatting strings had; not to throw the old methods away and force god-knows how many projects to use f-string's if they want their code to work for Python 3.6+.


As for the performance of these, it seems my initial suspicion that they might be slower is wrong, f-strings seem to easily outperform their .format counterparts:

โžœ cpython git:(master) ./python -m timeit -s "a = 'test'" "f'formatting a string {a}'"
500000 loops, best of 5: 628 nsec per loop
โžœ cpython git:(master) ./python -m timeit "'formatting a string {a}'.format(a='test')"
100000 loops, best of 5: 2.03 usec per loop

These were done against the master branch of the CPython repository as of this writing; they are definitely subject to change:

  • f-strings, as a new feature, might have possible optimizations
  • Optimizations to CPython might make .format faster (e.g Speedup method calls 1.2x)

But really, don't worry about speed so much, worry about what is more readable to you and to others.

In many cases, that's going to be f-strings, but there's some cases where format is better.

Answer from Dimitris Fasarakis Hilliard on Stack Overflow
Top answer
1 of 6
107

I'm afraid that it will be deprecated during the next Python versions

Don't be, str.format does not appear (nor has a reason) to be leaving any time soon, the PEP that introduced fprefixed-strings even states in its Abstract:

This PEP does not propose to remove or deprecate any of the existing string formatting mechanisms.

Formatted strings were introduced to address some of the shortcomings other methods for formatting strings had; not to throw the old methods away and force god-knows how many projects to use f-string's if they want their code to work for Python 3.6+.


As for the performance of these, it seems my initial suspicion that they might be slower is wrong, f-strings seem to easily outperform their .format counterparts:

โžœ cpython git:(master) ./python -m timeit -s "a = 'test'" "f'formatting a string {a}'"
500000 loops, best of 5: 628 nsec per loop
โžœ cpython git:(master) ./python -m timeit "'formatting a string {a}'.format(a='test')"
100000 loops, best of 5: 2.03 usec per loop

These were done against the master branch of the CPython repository as of this writing; they are definitely subject to change:

  • f-strings, as a new feature, might have possible optimizations
  • Optimizations to CPython might make .format faster (e.g Speedup method calls 1.2x)

But really, don't worry about speed so much, worry about what is more readable to you and to others.

In many cases, that's going to be f-strings, but there's some cases where format is better.

2 of 6
42

To build on Jim's answer and address your performance concern, I used python's dis module to compare the bytecode instructions for two syntactically different, but functionally equivalent functions.

import dis

def f1():
    a = "test"
    return f"{a}"

def f2():
    return "{a}".format(a='test')

print(dis.dis(f1))
print(dis.dis(f2))

The result of which is:

 11           0 LOAD_CONST               1 ('test')
              2 STORE_FAST               0 (a)

 12           4 LOAD_FAST                0 (a)
              6 FORMAT_VALUE             0
              8 RETURN_VALUE
None
 15           0 LOAD_CONST               1 ('{a}')
              2 LOAD_ATTR                0 (format)
              4 LOAD_CONST               2 ('test')
              6 LOAD_CONST               3 (('a',))
              8 CALL_FUNCTION_KW         1
             10 RETURN_VALUE
None

One can see that the f-string handles the formatting without attribute or function calls, which can impose type checking and memory overhead. According to timeit this results in a roughly 3x performance gain (for my specific functions)

>>> timeit.timeit('f1()', 'from __main__ import f1', number=100000)
0.012325852433775708
>>> timeit.timeit('f2()', 'from __main__ import f2', number=100000)
0.036395029920726074
Discussions

python - Which one? f string or using format in python3 - Stack Overflow
Some times when I used F string for Directory and file path I got some errors but there were no problem with using format. ... Better might be subjective, but the realpython website has a nice arcticle on why you should use one or the other. realpython.com/python-f-strings . More on stackoverflow.com
๐ŸŒ stackoverflow.com
What's better to use? (%), (f"string") or (.format())?
There's no rule, it's always about what you find the most readable. In almost all cases, f-strings will most likely be the winner. There is a reason they were introduced. More on reddit.com
๐ŸŒ r/learnpython
51
49
November 25, 2024
str.format() vs f"abc{my_var}" ?
F-strings are more readable and faster, but .format is backwards compatible with earlier python versions More on reddit.com
๐ŸŒ r/Python
32
2
July 13, 2018
python - String formatting: % vs. .format vs. f-string literal - Stack Overflow
There are various string formatting methods: Python More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Real Python
realpython.com โ€บ python-f-strings
Python's F-String for String Interpolation and Formatting โ€“ Real Python
November 30, 2024 - Python's f-strings provide a readable way to interpolate and format strings. They're readable, concise, and less prone to error than traditional string interpolation and formatting tools, such as the .format() method and the modulo operator ...
๐ŸŒ
Medium
medium.com โ€บ @DahlitzF โ€บ pythons-f-strings-vs-str-e22995cefef6
Pythonโ€™s f-strings vs. str()
December 26, 2018 - To summarize f-strings are faster than str() in terms of converting integers and such types to string. But keep in mind, that we only had a look at simple types. How they perform on more complex types is currently out of my knowledge as I didnโ€™t ...
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ format-vs-f-string-akhilesh-singh
format() vs f-String
April 6, 2023 - In conclusion, f-strings are faster than str.format() because they are evaluated at a phase that is closer to compile-time within Python's interpretation process, which reduces the amount of work that needs to be done at runtime.
๐ŸŒ
Medium
sinhassatyam.medium.com โ€บ python-string-formatting-f-strings-vs-format-vs-aa97693b7244
โšก Python String Formatting: F-strings vs .format() vs % | by Satyam Sinha | Medium
December 1, 2025 - F-strings are compiled into a highly efficient sequence of operations that load constant strings, evaluate expressions, and concatenate the results directly. The parsing overhead happens at compile time, not at runtime. When the compiler sees f"val: {x}", it generates code to: load the constant parts, evaluate x, format it, and then join them. # Until Python3.11 then modified in Python3.12+ # Bytecode for f"Value: {value:.2f}" (simplified) 2 0 LOAD_CONST 1 ('Value: ') 2 LOAD_NAME 0 (value) 4 FORMAT_VALUE 0 (FVC_NONE) 6 BUILD_STRING 2 # Since Python3.12 PI = 3.14159 dis.dis(lambda: f"pi value:{
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 61368640 โ€บ which-one-f-string-or-using-format-in-python3
python - Which one? f string or using format in python3 - Stack Overflow
format would remain the only option in certain dynamic settings (consider that "This is for {}".format is a bound method like any other) and for backwards compatibility, but all things being equal, prefer an f-string.
Find elsewhere
๐ŸŒ
Python
peps.python.org โ€บ pep-0498
PEP 498 โ€“ Literal String Interpolation | peps.python.org
These include %-formatting [1], str.format() [2], and string.Template [3]. Each of these methods have their advantages, but in addition have disadvantages that make them cumbersome to use in practice. This PEP proposed to add a new string formatting mechanism: Literal String Interpolation. In this PEP, such strings will be referred to as โ€œf-stringsโ€, taken from the leading character used to denote such strings, and standing for โ€œformatted stringsโ€.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what's better to use? (%), (f"string") or (.format())?
r/learnpython on Reddit: What's better to use? (%), (f"string") or (.format())?
November 25, 2024 -

I was trying to make a, silly program in which you can do some random things. I used arguments (%)in the past, but it's a bit hard to write like the identification of the variable, like there is so much types (%s, %f, %2f, %d, %g, %e...) and I want to take the easiest to write or the easiest to debug.

here are some examples of using each one:

  using (%):
name = "Imaginary_Morning"
age = 13
print("This profile is called %s and it has %d years old." % (name, age))
  
using (f"string"):
name = "Imaginary_Morning"
age = 13
print(f"This profile is called {name} and it has {age} years old.")

  using (.format()):
name = "Imaginary_Morning"
age = 13
print("This profile is called {} and it has {} years old.".format(name, age))
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-f-string
Python f-string: A Complete Guide | DataCamp
December 3, 2024 - Beyond readability, f-strings shine in performance. They're faster than both %-formatting and str.format() because they're evaluated at runtime rather than requiring multiple string operations. Python optimizes f-string evaluation, making them an efficient choice for string formatting.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ formatted-string-literals-f-strings-python
f-strings in Python - GeeksforGeeks
June 19, 2024 - To create an f-string, prefix the ... way that you would with str.format(). F-strings provide a concise and convenient way to embed Python expressions inside string literals for formatting....
๐ŸŒ
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
string. The letter 'f' also indicates that these strings are used for formatting. Although there are ยท other ways for formatting strings, the Zen of Python states that simple is better than complex
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - Python f-string is a powerful and flexible string formatting method introduced in Python 3.6. Unlike older formatting techniques such as %-based formatting and str.format(), f-strings are faster, more readable, and less prone to errors.
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ str.format() vs f"abc{my_var}" ?
r/Python on Reddit: str.format() vs f"abc{my_var}" ?
July 13, 2018 -

Hey settle an argument with my and my friend. We're working on a project together and he keeps suggesting str.format() and I keep persisting on the f"{}" syntax.

which is "best" ? (we're not doing intensive string operations)

๐ŸŒ
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.
๐ŸŒ
Cybrosys Technologies
cybrosys.com โ€บ odoo blogs
Comparison Between Python's F-strings & Traditional String Formatting
October 10, 2023 - in this comprehensive article, we will dive deep into the power and simplicity of f-strings, a modern string formatting technique introduced in Python 3.6.
Top answer
1 of 16
994

To answer your first question... .format just seems more sophisticated in many ways. An annoying thing about % is also how it can either take a variable or a tuple. You'd think the following would always work:

"Hello %s" % name

yet, if name happens to be (1, 2, 3), it will throw a TypeError. To guarantee that it always prints, you'd need to do

"Hello %s" % (name,)   # supply the single argument as a single-item tuple

which is just ugly. .format doesn't have those issues. Also in the second example you gave, the .format example is much cleaner looking.

Only use it for backwards compatibility with Python 2.5.


To answer your second question, string formatting happens at the same time as any other operation - when the string formatting expression is evaluated. And Python, not being a lazy language, evaluates expressions before calling functions, so the expression log.debug("some debug info: %s" % some_info) will first evaluate the string to, e.g. "some debug info: roflcopters are active", then that string will be passed to log.debug().

2 of 16
320

Something that the modulo operator ( % ) can't do, afaik:

tu = (12,45,22222,103,6)
print '{0} {2} {1} {2} {3} {2} {4} {2}'.format(*tu)

result

12 22222 45 22222 103 22222 6 22222

Very useful.

Another point: format(), being a function, can be used as an argument in other functions:

li = [12,45,78,784,2,69,1254,4785,984]
print map('the number is {}'.format,li)   

print

from datetime import datetime,timedelta

once_upon_a_time = datetime(2010, 7, 1, 12, 0, 0)
delta = timedelta(days=13, hours=8,  minutes=20)

gen =(once_upon_a_time +x*delta for x in xrange(20))

print '\n'.join(map('{:%Y-%m-%d %H:%M:%S}'.format, gen))

Results in:

['the number is 12', 'the number is 45', 'the number is 78', 'the number is 784', 'the number is 2', 'the number is 69', 'the number is 1254', 'the number is 4785', 'the number is 984']

2010-07-01 12:00:00
2010-07-14 20:20:00
2010-07-28 04:40:00
2010-08-10 13:00:00
2010-08-23 21:20:00
2010-09-06 05:40:00
2010-09-19 14:00:00
2010-10-02 22:20:00
2010-10-16 06:40:00
2010-10-29 15:00:00
2010-11-11 23:20:00
2010-11-25 07:40:00
2010-12-08 16:00:00
2010-12-22 00:20:00
2011-01-04 08:40:00
2011-01-17 17:00:00
2011-01-31 01:20:00
2011-02-13 09:40:00
2011-02-26 18:00:00
2011-03-12 02:20:00
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ introducing f-strings - the best option for string formatting in python
Introducing f-Strings - The Best Option for String Formatting in Python | Towards Data Science
January 26, 2025 - In a nutshell, f-Strings provide a cleaner and easier to manage way for formatting strings. Plus, they are a lot faster. You should use them whenever possible if you have access to Python 3.6 or a newer version.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why do people use .format() method when f string literal exists?
r/learnpython on Reddit: Why do people use .format() method when f string literal exists?
July 1, 2020 -

Hello all,

I seem to encounter a lot of documentation and tutorials that use .format() method instead of f string literals.

Personally,

print("I can't seem to {} of a {} why someone {} {} {}".format('think', 'reason', 'would', 'prefer', 'this'))

versus

easily = "easily"
sentence = "sentence"
this = "this"
print(f"A much more {easily} readable {sentence} such as {this}")

F string literal is always much easier to decipher and thus avoid errors.

Perhaps there's some benefit of .format() that I'm unaware of. Googling hasn't brought up much on the debate.

Cheers!

๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-f-strings-tutorial-how-to-use-f-strings-for-string-formatting
Python f-String Tutorial โ€“ String Formatting in Python Explained with Code Examples
September 14, 2021 - When you're formatting strings in Python, you're probably used to using the format() method. But in Python 3.6 and later, you can use f-Strings instead. f-Strings, also called formatted string literals, have a more succinct syntax and can be ...