In Python 3.6 f-strings are introduced.

You can write like this

print (f"So, you're {age} old, {height} tall and {weight} heavy.")

For more information Refer: https://docs.python.org/3/whatsnew/3.6.html

Answer from Nithin R on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-output-formatting
Python - Output Formatting - GeeksforGeeks
... # string modulo operator(%) print("Geeks : -, Portal : %5.2f" % (1, 05.333)) print("Total students : =, Boys : -" % (240, 120)) # print integer value print("%7.3o" % (25)) # print octal value print(".3E" % (356.08977)) # print exponential value
Published   July 11, 2025
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.3 documentation
An optional format specifier can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal: >>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142.
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
A modifier is included by adding a colon : followed by a legal formatting type, like .2f which means fixed point number with 2 decimals: ... You can perform Python operations inside the placeholders. ... price = 59 tax = 0.25 txt = f"The price is {price + (price * tax)} dollars" print(txt) Try it Yourself »
🌐
PyFormat
pyformat.info
PyFormat: Using % and .format() for great good!
Of course it is also possible to format numbers. ... Similar to strings numbers can also be constrained to a specific width. ... Again similar to truncating strings the precision for floating point numbers limits the number of positions after the decimal point. For floating points the padding value represents the length of the complete output. In the example below we want our output to have at least 6 characters with 2 after the decimal point.
🌐
Real Python
realpython.com › python-formatted-output
A Guide to Modern Python String Formatting Tools – Real Python
February 1, 2025 - In this example, you have four replacement fields in the template but only three arguments in the call to .format(). So, you get an IndexError exception. Finally, it’s fine if the arguments outnumber the replacement fields. The excess arguments aren’t used: ... Here, Python ignores the "baz" argument and builds the final string using only "foo" and "bar".
🌐
Mooc
programming-25.mooc.fi › part-4 › 5-print-statement-formatting
Print statement formatting - Python Programming MOOC 2025
The first is the + operator for strings. It allows simple concatenation of string segments: name = "Mark" age = 37 print("Hi " + name + " your age is " + str(age) + " years" ) This method will not work if any of the segments are not strings. In the example above, the variable age has been converted ...
🌐
Python Course
python-course.eu › python-tutorial › formatted-output.php
22. Formatted Output | Python Tutorial | python-course.eu
Additionally, we can modify the formatting with the sign option, which is only valid for number types: ... Enjoying this page? We offer live Python training courses covering the content of this site. ... Just to mention it once more: We could have used empty curly braces in the previous example! Using keyword parameters: print("The capital of {province} is {capital}".format(province="Ontario",capital="Toronto"))
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-string-format-python-s-print-format-example
Python String Format – Python S Print Format Example
September 7, 2021 - ... rankings = {"Gonzaga": 31, "Baylor": 28, "Michigan": 25, "Illinois": 24, "Houston": 21} for team, score in rankings.items(): print(f"{team:10} ==> {score:10d}") Template strings are Python strings that use placeholders for the real values.
🌐
Bentley
cissandbox.bentley.edu › sandbox › wp-content › uploads › 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
Updated 2022 A Guide to Formatting with f-strings in Python
example of using f-strings for debugging purposes which will be covered later. import math · variable = math.pi · Formatting with f-strings Page | 2 · print(f"Using Numeric {variable = }") print(f"|{variable:25}|") print(f"|{variable:<25}|") print(f"|{variable:>25}|") print(f"|{variable:^25}|\n") variable = "Python 3.9" print(f"Using String {variable = }") print(f"|{variable:25}|") print(f"|{variable:<25}|") print(f"|{variable:>25}|") print(f"|{variable:^25}|") The output of this code snippet is: Using Numeric variable = 3.141592653589793 ·
🌐
Python
docs.python.org › fr › 3 › tutorial › inputoutput.html
7. Les entrées/sorties — Documentation Python 3.14.3
Given format % values (where format ... is commonly known as string interpolation. For example: >>> import math >>> print('The value of pi is approximately %5.3f.'...
🌐
TechBeamers
techbeamers.com › python-string-format
Python String Format() - TechBeamers
November 30, 2025 - A float data type also has a couple of variations which you can style using the Python format function. Let’s print a full floating point number. ... Now, let’s print a floating point number truncating after three decimal points. ... Finally, let’s print a floating point number that truncates after three decimal places but does round the final value. ... print('Fixed-point example: <{0:f}>'.format(2.2183)) #Fixed-point example: <2.218300> print('Fixed-point with right alignment example: <{0:25f}>'.format(2.2183)) #Fixed-point with right alignment example: < 2.218300> print('Fixed-point with precision and right alignment example: <{0:<25.10f}>'.format(2.2183)) #Fixed-point with precision and right alignment example: <2.2183000000 >
🌐
Python-Kurs
python-kurs.eu › python3_formatierte_ausgabe.php
Python3-Tutorial: Formatierte Ausgabe
Den mittels der String-Interpolation erzeugten formatierten String, kann man dann z.B. mittels print (also nicht printf) ausgeben. Aber man kann diesen formatierten String auch auf andere Art im Programm weiter verwenden, wie ihn zum Beispiel in eine Datenbank übertragen. Seit Python 2.6 eingeführt worden ist, wird jedoch von der Python-Gemeinde empfohlen die String-Methode "format" stattdessen zu verwenden.
🌐
mkaz.blog
mkaz.blog › code › python-string-format-cookbook
String Formatting - mkaz.blog
July 15, 2021 - name = "Python" version = 3.11 # F-strings (recommended) message = f"Welcome to {name} {version}!" # .format() method message = "Welcome to {} {}!".format(name, version) # % formatting (legacy) message = "Welcome to %s %s!" % (name, version) # All output: Welcome to Python 3.11! Performance comparison (Python 3.11): import timeit name = "World" # F-string: ~0.05 microseconds t = timeit.timeit(lambda: f"Hello {name}!", number=1000000) print("Time: {t:.6f} seconds") # .format(): ~0.15 microseconds t = timeit.timeit(lambda: "Hello {}!".format(name), number=1000000) print("Time: {t:.6f} seconds")
🌐
JournalDev
journaldev.com › 17370 › python-print-format
Python print() | DigitalOcean
August 4, 2022 - So, as many item you want to print, just put them together as arguments. If see the example of the previous section, you will notice that that variables are separated with a space. But you can customize it to your own style. Suppose in the previous code, you want to separate the values using underscore(_). Then you should pass underscore as the value of sep keyword. The following function will illustrate you the idea of using python print sep keyword.
🌐
Python
docs.python.org › 3.1 › tutorial › inputoutput.html
7. Input and Output — Python v3.1.5 documentation
September 4, 2012 - It interprets the left argument much like a sprintf()-style format string to be applied to the right argument, and returns the string resulting from this formatting operation. For example: >>> import math >>> print('The value of PI is approximately %5.3f.' % math.pi) The value of PI is ...
🌐
Python
docs.python.org › 3.4 › library › string.html
Python string formatting
String of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace. ... A string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab.
🌐
Codegrepper
codegrepper.com › code-examples › python › python+print+format
python print format Code Example
for x in numbers: print "{:10.4f}".format(x) prints 23.2300 0.1233 1.0000 4.2230 9887.2000