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.
🌐
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 ...
🌐
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.
🌐
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.
🌐
Vultr Docs
docs.vultr.com › python › standard-library › str › format
Python str format() - String Formatting | Vultr Docs
December 11, 2024 - python Copy · base_string = "Hello, {}!" formatted_string = base_string.format("Alice") print(formatted_string) Explain Code · This example injects the name "Alice" into the placeholder in base_string. The result is "Hello, Alice!". Create a string with multiple placeholders.