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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_string_formatting.asp
Python String Formatting
def myconverter(x): return x * 0.3048 txt = f"The plane is flying at a {myconverter(30000)} meter altitude" print(txt) Try it Yourself ยป ยท At the beginning of this chapter we explained how to use the .2f modifier to format a number into a fixed point number with 2 decimals. There are several other modifiers that can be used to format values: ... Here is a list of all the formatting types. Before Python 3.6 we used the format() method to format strings.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ inputoutput.html
7. Input and Output โ€” Python 3.14.6 documentation
Formatted string literals (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with f or F and writing expressions as {expression}. 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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-output-formatting
Python - Output Formatting - GeeksforGeeks
The string modulo operator (%) is one of the oldest ways to format strings in Python. It allows you to embed values within a string by placing format specifiers in the string. Each specifier starts with a % and ends with a character that represents the type of value being formatted. ... # 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
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ String_Formatting
String Formatting - Learn Python - Free Interactive Python Tutorial
# This prints out: A list: [1, 2, 3] mylist = [1,2,3] print("A list: %s" % mylist) Here are some basic argument specifiers you should know: %s - String (or any object with a string representation, like numbers) ... %.<number of digits>f - Floating point numbers with a fixed amount of digits to the right of the dot. %x/%X - Integers in hex representation (lowercase/uppercase) You will need to write a format string which prints out the data using the following syntax: Hello John Doe.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_format.asp
Python String format() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ยท โฎ String Methods ยท Insert the price inside the placeholder, the price should be in fixed point, two-decimal format: txt = "For only {price:.2f} dollars!" print(txt.format(price = 49)) Try it Yourself ยป ยท
๐ŸŒ
PyFormat
pyformat.info
PyFormat: Using % and .format() for great good!
With this site we try to show you the most common use-cases covered by the old and new style string formatting API with practical examples. All examples on this page work out of the box with with Python 2.7, 3.2, 3.3, 3.4, and 3.5 without requiring any additional libraries.
๐ŸŒ
Stuy
bert.stuy.edu โ€บ pbrooks โ€บ IntroResources โ€บ print_string_formatting.html
Print/string formatting
> pi=3.141592653 > last="Potter" ... to insert into the formatting string, enclose the variables inside parentheses: > print 'Official name: %s, %s' % (last,first) Official name: Potter, Harry > #### Use %f for floating point numbers (let Python choose the number of decimal ...
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 - Here is the basic syntax for the str.format() method: ... Inside the template string, we can use {} which act as placeholders for the arguments. The arguments are values that will be displayed in the string.
๐ŸŒ
Python Course
python-course.eu โ€บ python-tutorial โ€บ formatted-output.php
22. Formatted Output | Python Tutorial | python-course.eu
One can go as far as to say that this answer is not true. So there is a "printf" in Python? No, but the functionality of the "ancient" printf is contained in Python. To this purpose the modulo operator "%" is overloaded by the string class to perform string formatting.
๐ŸŒ
Real Python
realpython.com โ€บ python-formatted-output
A Guide to Modern Python String Formatting Tools โ€“ Real Python
February 1, 2025 - You create an f-string in Python by prepending a string literal with an f or F and using curly braces to include variables or expressions. You can use variables in Pythonโ€™s .format() method by placing them inside curly braces and passing them ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-formatting-python-print-statements-91
Python Basics | Print() Function | Format Specifiers | f-Strings | LabEx
## print a float with a width of 10 and a precision of 2 print("The value of pi is approximately .2f." % 3.14159) This will output the string "The value of pi is approximately 3.14." to the console, with the float value right-aligned in a field of width 10 and a precision of 2. f-strings (short for formatted strings) are a more recent addition to Python and provide a concise and convenient way to embed expressions inside string literals, using {} placeholders.
๐ŸŒ
OpenStax
openstax.org โ€บ books โ€บ introduction-python-programming โ€บ pages โ€บ 8-4-string-formatting
8.4 String formatting - Introduction to Python Programming | OpenStax
March 13, 2024 - Format a string template using input arguments. Use format() to generate numerical formats based on a given template. Python provides string substitutions syntax for formatting strings with input arguments.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-format-method
Python String format() Method - GeeksforGeeks
March 26, 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.
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-string-formatting
Pythonโ€™s String format() Cheat Sheet | LearnPython.com
We wonโ€™t be spending any more time talking about it โ€“ except to mention that it could be useful when dealing with older versions of Python. As of Python 3, string formatting is performed chiefly using the format() function, which belongs ...
๐ŸŒ
Codesolid
codesolid.com โ€บ python-format-strings
Python Format Strings: Beginner to Expert โ€” CodeSolid.com 0.1 documentation
String formatting is the process ... how to format using string concatenation and print, but more flexible techniques include f strings and the string format method. String formatting is an essential skill for any Python programmer to master....
๐ŸŒ
mkaz.blog
mkaz.blog โ€บ working-with-python โ€บ string-formatting
Python String Formatting: Complete Guide - mkaz.blog
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")
๐ŸŒ
LabEx
labex.io โ€บ home โ€บ cheatsheet โ€บ string formatting
Python String Formatting - Python Cheat Sheet
# % operator: old-style string formatting (not recommended for new code) name = 'Pete' 'Hello %s' % name # %s = string placeholder ... Python 3 introduced a new way to do string formatting that was later back-ported to Python 2.7.
๐ŸŒ
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
Prints the number in scientific notation using the letter โ€˜eโ€™ ยท to indicate the exponent. The default precision is 6. ... Fixed-point notation. Displays the number as a fixed-point number. The ... Percentage. Multiplies the number by 100 and displays in fixed ('f') format, ... The variable, variable, is enclosed in curly braces { }. When variable = 10, the f-string...
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ formatted-strings
Python Formatted Strings / f-string formatting Guide
Start your coding journey with Python. Learn basics, data types, control flow, and more ... name = "Alice" item_count = 5 price = 19.99 # Basic f-string usage greeting = f"Hello, {name}." print(greeting) # Outputs: Hello, Alice. # Using expressions and number formatting total_cost = item_count * price receipt = f"Your total is ${total_cost:.2f} for {item_count} items." print(receipt) # Outputs: Your total is $99.95 for 5 items.