It has the advantage of being able to put variables after instead of having to do it at the time that the string is created. As an example, if I want to print a format for a list (to make it look like a table), I can re-use a .format() string like so: table_fmt = "name: {:8} age: {:8} weight: {:3}" items_1 = ("John", 35, 180) items_2 = ("Susan", 35, 130) print(table_fmt.format(*items_1)) print(table_fmt.format(*items_2)) Or if I want to print in a different order, I can also do something like: order = ("Pizza", 25.00, "Visa", "ACCEPTED") fmt = "status: {3}, item: {0}, cost: {1}, payment method: {2}" print(fmt.format(*order)) You can also put in a function result in a .format() string without it breaking the readability, while the same isn't true for f-strings: value = 20.0 def price_after_taxes(cost): return cost * 1.05 print("After taxes, you have to pay {} for your pizza".format(price_after_taxes(cost))) So it is useful in some cases, although f strings usually are a lot faster and nicer to read. It's a tradeoff between readability and flexibility. Answer from siddsp on reddit.com
🌐
Real Python
realpython.com › ref › builtin-functions › format
format() | Python’s Built-in Functions – Real Python
The function takes a format specification, format_spec, which determines how the value should be formatted: ... Returns a formatted string representation of the input value according to the specified format.
🌐
W3Schools
w3schools.com › python › ref_string_format.asp
Python String format() Method
Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Matplotlib Intro Matplotlib Get Started Matplotlib Pyplot Matplotlib Plotting Matplotlib Markers Matplotlib Line Matplotlib ...
Discussions

Is .format() still efficient and used?
It has the advantage of being able to put variables after instead of having to do it at the time that the string is created. As an example, if I want to print a format for a list (to make it look like a table), I can re-use a .format() string like so: table_fmt = "name: {:8} age: {:8} weight: {:3}" items_1 = ("John", 35, 180) items_2 = ("Susan", 35, 130) print(table_fmt.format(*items_1)) print(table_fmt.format(*items_2)) Or if I want to print in a different order, I can also do something like: order = ("Pizza", 25.00, "Visa", "ACCEPTED") fmt = "status: {3}, item: {0}, cost: {1}, payment method: {2}" print(fmt.format(*order)) You can also put in a function result in a .format() string without it breaking the readability, while the same isn't true for f-strings: value = 20.0 def price_after_taxes(cost): return cost * 1.05 print("After taxes, you have to pay {} for your pizza".format(price_after_taxes(cost))) So it is useful in some cases, although f strings usually are a lot faster and nicer to read. It's a tradeoff between readability and flexibility. More on reddit.com
🌐 r/learnpython
44
83
March 3, 2022
What does format() in Python actually do? - Stack Overflow
Curly braces {} are used as placeholders, and the value we wish to put in the placeholders are passed as parameters into the format function. If you have more than one placeholder in the string, python will replace the placeholders by values, in order. More on stackoverflow.com
🌐 stackoverflow.com
Understanding the format function in python - Stack Overflow
Our team prefers to use format instead of str.format in every case, and while trying to learn how to use format() in Python I encountered something which I have no idea of why it happened, and thi... More on stackoverflow.com
🌐 stackoverflow.com
Why do people use .format() method when f string literal exists?
f-strings exist for convenience. In doing so, they sacrifice portability, flexibility, and functionality. They are not back-wards compatible with python3.5, which is still floating around out there. They also have some drawbacks, like with the normal format method, you can re-use values, e.g. '{0}, {0}, and {1}'.format('ham', 'spam') Can't do that with f-strings. you can also build dynamically formatted strings: a = range(5) ( '{}'*len(a) ).format(*a) Which can be quite complex. there are probably more reasons others will comment about, but in general, f-strings are just for hard-coded generic messages that aren't anything special. the format function is still very necessary. More on reddit.com
🌐 r/learnpython
101
338
March 12, 2020
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 weeks ago - If you want to convert an integer ... % 255, '%x' % 255, '%X' % 255 ('0xff', 'ff', 'FF') >>> format(255, '#x'), format(255, 'x'), format(255, 'X') ('0xff', 'ff', 'FF') >>> f'{255:#x}', f'{255:x}', f'{255:X}' ('0xff', 'ff', ...
🌐
Programiz
programiz.com › python-programming › methods › built-in › format
Python format()
... The format() method returns a formatted value based on the specified formatter. ... # format the integer to binary binary_value = format(value, 'b') print(binary_value) # Output: 101101 ... The format() function returns a value in the string representation of the desired format.
🌐
Edureka
edureka.co › blog › format-function-in-python
Format Function in Python | Python fomrat() Function Examples | Edureka
November 27, 2024 - Format Function in Python (str.format()) is technique of the string category permits you to try and do variable substitutions and data formatting.
🌐
Scaler
scaler.com › home › topics › format in python
Format in Python | Format Function in Python - Scaler Topics
May 18, 2022 - There are two types of format functions in Python, one is the format() function which is used to convert a value to a formatted representation, and the other is the str.format() method used to insert variables in a string without having to ...
🌐
PyFormat
pyformat.info
PyFormat: Using % and .format() for great good!
The new-style simple formatter calls by default the __format__() method of an object for its representation. If you just want to render the output of str(...) or repr(...) you can use the !s or !r conversion flags. In %-style you usually use %s for the string representation but there is %r for a repr(...) conversion. class Data(object): def __str__(self): return 'str' def __repr__(self): return 'repr' ... In Python 3 there exists an additional conversion flag that uses the output of repr(...) but uses ascii(...) instead.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-format-method
Python String format() Method - GeeksforGeeks
July 11, 2025 - When a string requires multiple values to be inserted, we use multiple placeholders {}. The format() method replaces each placeholder with the corresponding value in the provided order.
🌐
Reddit
reddit.com › r/learnpython › is .format() still efficient and used?
r/learnpython on Reddit: Is .format() still efficient and used?
March 3, 2022 -

I have been learning Python for a few days now. I learnt about f-strings, they seem a lot more easy to me than the .format() method. Because you can immediately call in the variables inside the strings. And I looked up a few other resources while learning, some are still using .format() method. Does it have any advantages over f-strings or it's just a matter of choice?

Top answer
1 of 3
3

You can definitely use a variable in the string example that you have shown, in the following manner:

my_name = "Melanie"
Output = "My name is " + my_name + "."
print(Output)

My name is Melanie.

This is the easy way, but not the most elegant.

In the above example, I have used 3 lines and created 2 variables (my_name and Output)

However, I can get the same output using just one line of code and without creating any variables, using format()

print("My name is {}.".format("Melanie"))

My name is Melanie.

Curly braces {} are used as placeholders, and the value we wish to put in the placeholders are passed as parameters into the format function.

If you have more than one placeholder in the string, python will replace the placeholders by values, in order.

Just make sure that the number of values passed as parameters to format(), is equal to the number of placeholders created in the string.

For example:

print("My name is {}, and I am {}.".format("Melanie",26))

My name is Melanie, and I am 26.

There are 3 different ways to specify placeholders and their values:

Type 1:

print("My name is {name}, and I am {age}.".format(name="Melanie", age=26))

Type 2:

print("My name is {0}, and I am {1}.".format("Melanie",26))

Type 3:

print("My name is {}, and I am {}.".format("Melanie",26))

Additionally, by using format() instead of a variable, you can:

  1. Specify the data type, and
  2. Add a formatting type to format the result.

For example:

print("{0:^7} has completed {1:.3f} percent of task {2}".format("Melanie",75.765367,1))

Melanie has completed 75.765 percent of task 1.

I have set the data type for the percentage field to be a float, with 3 decimals, and given a character length of 7 to the name, and center-aligned it.

The alignment codes are:

' < ' :left-align text

' ^ ' :center text

' > ' :right-align

The format() method is helpful when you have multiple substitutions and formattings to perform on a string.

2 of 3
2

An example using the format function is this:

name =  Arnold
age = 5

print("{ }, { }".format(name, age))

This displays:

Arnold, 5
🌐
ProjectPro
projectpro.io › recipes › use-format-function-python
How to use format function in Python? -
August 3, 2022 - In python, string format() method formats a given string into a pleasant output by inserting some specified values into the string's placeholder. The placeholder is defined using curly brackets: {}. There are a lot of ways in which we can use ...
🌐
Python
docs.python.org › 3 › library › string.html
Common string operations — Python 3.14.3 documentation
It is exposed as a separate function for cases where you want to pass in a predefined dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the *args and **kwargs syntax. vformat() does the work of breaking up the format string into character data and replacement fields.
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › format function in python
Format Function in Python | Interview Kickstart
A software developer deals with strings all the time, and handling complex strings efficiently is crucial. Python 3.0 recognizes the need for more efficiency in this area and therefore has introduced a method in its built-in string class. This method is the format() function, which we’ll cover in this article.
Address   4701 Patrick Henry Dr Bldg 25, 95054, Santa Clara
(4.7)
🌐
Codecademy
codecademy.com › docs › python › strings › .format()
Python | Strings | .format() | Codecademy
July 27, 2022 - The .format() string function returns a string with values inserted via placeholders. Python’s built-in string function .format() converts strings by inserting values passed through placeholders.
🌐
W3Schools
w3schools.com › python › ref_func_format.asp
Python format() Function
Python Examples Python Compiler ... Python Certificate Python Training ... The format() function formats a specified value into a specified format....
🌐
Simplilearn
simplilearn.com › home › resources › software development › your ultimate python tutorial for beginners › guide to string formatting in python
Guide To String Formatting In Python | Simplilearn
October 15, 2022 - Learn how to format string Python in different ways. String formatting is the process of inserting a custom string or variable in predefined text. Read Now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
AskPython
askpython.com › home › python format() function
Python format() function - AskPython
August 6, 2022 - Python format() function enables us to separate the numeric values using "," as a separator. ... The separator i.e. “,” is added after three digits in a manner that it works for the thousands place in the number system.
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.3 documentation
So far we’ve encountered two ... print() function. (A third way is using the write() method of file objects; the standard output file can be referenced as sys.stdout. See the Library Reference for more information on this.) Often you’ll want more control over the formatting of your output ...
🌐
Stack Overflow
stackoverflow.com › questions › 46398842 › understanding-the-format-function-in-python
Understanding the format function in python - Stack Overflow
Everything else is left-aligned by default. This is clear in the docs. Read them: docs.python.org/3/library/string.html#formatspec ... A call to format(value, format_spec) is translated to type(value).__format__(value, format_spec). format internally calls each type's __format__ function.
🌐
Learn Python
learnpython.org › en › String_Formatting
String Formatting - Learn Python - Free Interactive Python Tutorial
Your current balance is $53.44.", no_output_msg= "Make sure you add the `%s` in the correct spaces to the `format_string` to meeet the exercise goals!") test_object('format_string') success_msg('Great work!') This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science.