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
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ inputoutput.html
7. Input and output โ€” Python 3.15.0 documentation
This is particularly useful in combination with the built-in function vars(), which returns a dictionary containing all local variables: >>> table = {k: str(v) for k, v in vars().items()} >>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()]) >>> print(message.format(**table)) __name__: __main__; __doc__: None; __package__: None; __loader__: ... As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes:
๐ŸŒ
Real Python
realpython.com โ€บ python-print
Your Guide to the Python print() Function โ€“ Real Python
July 3, 2026 - By using a semicolon (;), you can place multiple Python statements on a single line. Although this enhances readability in this particular example, itโ€™s usually better to follow standard formatting practices for clarity. You can implement the individual functions that appear in the example above in merely ten lines of code: ... from time import sleep speed = 0.1 def signal(duration, symbol): sleep(duration) print(symbol, end="", flush=True) dot = lambda: signal(speed, "ยท\a") dash = lambda: signal(3*speed, "โˆ’\a") symbol_space = lambda: signal(speed, "") letter_space = lambda: signal(3*speed, "") word_space = lambda: signal(7*speed, " ") # ...
Discussions

python - How to print formatted string in Python3? - Stack Overflow
Sure, but the OP was using Python 3.4. 2019-10-20T17:07:50.143Z+00:00 ... Save this answer. ... Show activity on this post. You need to apply your formatting to the string, not to the return value of the print() function: More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is the function of ':g' in the python f-string?
Best explanation I could find https://stackoverflow.com/questions/41840613/understanding-the-python-g-in-string-formatting-achieving-java-string-format-b More on reddit.com
๐ŸŒ r/learnpython
22
87
January 18, 2022
Using commas (,) instead of plus (+)

In your second example, you're passing five arguments to print.print will then automatically convert all of its arguments to strings and print them separated with spaces. In your first example, you're building up one big string, and then passing it as a single argument to print. You can also use string formatting to a similar effect: print("The product: {} costs {} dollars".format(product, price)), or even print(f"The product: {product} costs {price} dollars") if you're using Python 3.6.

More on reddit.com
๐ŸŒ r/Python
20
5
November 10, 2017
How to get float to two decimal places without rounding off.
Using only math, I believe you can do this: >>> f = 8.225 >>> f - f % 0.01 8.22 Using strings you can do something like this: >>> float(str(f)[:4]) 8.22 Some more examples of the first one just for fun: >>> r = lambda f: f - f % 0.01 >>> r(2.368) 2.36 >>> r(2.36888888) 2.36 >>> r(2.323) 2.32 >>> r(2.326) 2.32 Doesn't work with a single decimal, but works with 2 or more: >>> r = lambda f,p: f - f % p >>> r(2.356366,0.1) 2.3000000000000003 >>> r(2.356366,0.01) 2.35 >>> r(2.356366,0.001) 2.356 >>> r(2.356366,0.0001) 2.3563 >>> r(2.356366,0.00001) 2.35636 More on reddit.com
๐ŸŒ r/learnpython
7
5
June 10, 2016
People also ask

What is the print() function in Python?
The print() function in Python shows output on the screen. You can use it to display text, numbers, or results from your code. Itโ€™s one of the most used commands in any Python program.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ print-function
Python Print Function: With Syntax & Examples
Can I format text while using print in Python?
Yes, Python allows formatting using f-strings, format() method, or string concatenation. For example: print(f"Hello, {name}") gives you a clean and readable way to format your output.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ print-function
Python Print Function: With Syntax & Examples
How do I use the Python print statement with variables?
Just put the variable inside the print() function like this: print(name). You can also mix text and variables: print("Hello", name) to make the message dynamic.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ print-function
Python Print Function: With Syntax & Examples
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-formatting-python-print-statements-91
Python Basics | Print() Function | Format Specifiers | f-Strings | LabEx
For example: ## 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 ...
๐ŸŒ
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 Course
python-course.eu โ€บ python-tutorial โ€บ formatted-output.php
22. Formatted Output | Python Tutorial | python-course.eu
"string format" is by far the most flexible and Pythonic approach. So far we have used the print function in two ways, when we had to print out more than two values: ... We used print with a comma separated list of values to print out the results, as we can see in the following example.
Find elsewhere
๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ print-format-in-python
Python print() function | Board Infinity
August 9, 2025 - This method comes very handy when you are printing some data or you want to print things in a similar format now consider โ€˜cโ€™ is Russians and โ€˜dโ€™ is Pizza and you can just call this method and you have to just change these values and you will see Russians love Pizza. ... This print function behaves as a template and one more thing about the print function is that it also supports C language type printing what it means is you can have a print percentage let's say it is again 10 B is 20 and you want to print numbers right so suppose you entered a number โ€˜aโ€™ which is %d and B it so yo
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ python โ€บ print-function
Python Print Function: With Syntax & Examples
August 6, 2026 - Master the Python print() function: syntax, examples & parameters (sep, end, flush) explained simply. Practice with hands-on code in this free tutorial.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ python-print-function
Python print Function
August 10, 2026 - name = 'Tutorial Gateway' person = 'suresh' year = 2019 print('%s is working at %s' %(person, name)) print(person + ' is working at ' + name) ... In this example, we are using the format function inside this function.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ print-function.aspx
Python print() function: Format, Code, Arguments, Examples
Any message and variables are ... = "Anshu Shukla" age = 21 marks = [80, 85, 92] perc = 85.66 # Printing print("Name:", name) print("Age:", age) print("Marks:", marks) print("Percentage:", perc)...
๐ŸŒ
Medium
medium.com โ€บ @raidivya โ€บ python-print-function-0bcc7e44df45
Python: print() Function. The print() function outputs text andโ€ฆ | by Divya Rai | Medium
June 23, 2024 - # Example 3: Using sep and end parameters print("Hello", "World", sep=", ", end="!") print("Welcome to Python.") sep=", ": Separates objects with a comma and a space. end="!": Ends the print statement with an exclamation mark instead of a newline.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ print-function
Explore Python's print() function, master output customization
import os current_directory = os.getcwd() print(f"Current Directory: {current_directory}") ### **Boolean Values and Printing** The `print()` function can handle boolean values, outputting either `True` or `False`. ```python condition = 5 > 3 print(condition) # Outputs: True ยท Using keyword arguments like sep and end allows you to control the format and structure of printed output.
๐ŸŒ
Wiingy
wiingy.com โ€บ home โ€บ learn โ€บ python โ€บ output formatting in python
Output Formatting in Python
January 30, 2025 - This can include manipulating the size, shape, color, and other properties of text and visual elements to make the data more visually appealing and easier to understand. Python provides various tools and libraries for output formatting, including built-in functions like print() and more advanced options like string formatting and regular expressions.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_output_formatting.htm
Python - Output Formatting
It is the official string representation of Python object. When we use object as parameter to print() function it prints return value of repr() function. In this example, the __repr__() method returns the string representation of player object โˆ’ ยท import pprint class player: def __init__(self, name, formats=[], runs=[]): self.name=name self.formats=formats self.runs=runs def __repr__(self): dct={} dct[self.name]=dict(zip(self.formats,self.runs)) return (repr(dct)) l1=['Tests','ODI','T20'] l2=[[140, 45, 39],[15,122,36,67, 100, 49],[78,44, 12, 0, 23, 75]] p1=player("virat",l1,l2) pp=pprint.PrettyPrinter() pp.pprint(p1)
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ format
Python format()
# using '+' and '-' format specifier positive_with_plus = format(123, '+') positive_with_minus = format(123, '-') print("Positive with '+':", positive_with_plus) print("Positive with '-':", positive_with_minus) ... In the above example, we formatted the numbers 123 and -123 using each of the ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-string-format-python-s-print-format-example
Python String Format โ€“ Python S Print Format Example
September 7, 2021 - Inside the for loop, we can use an f-string to format the printed results. The use of the : for {team:10} and {score:10d} tells the computer to create a field that is 10 characters wide. This will create even columns for the data.
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-print-statement.php
Python print() function
The simplest way to use the print() function is by passing a string or variable as an argument: ... print("Python", "is", "fun", sep="-") # Output: Python-is-fun print("Hello", end=", ") print("world!") # Output: Hello, world!
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ format-function-in-python
Format Function in Python | Python fomrat() Function Examples | Edureka
November 27, 2024 - In the example below, you will be able to see the implementation of the format in the print statement. Apart from directly using in the print statement, we can also use format() to a variable: ... Letโ€™s say if there is another variable substitution required in a sentence, this can be done by adding another set of curly brackets where we want substitution and passing a second value into format(). Python ...
๐ŸŒ
Medium
medium.com โ€บ @clarazheng111 โ€บ understanding-and-using-the-print-function-in-python-4c2d600c1980
Understanding and Using the print Function in Python | by Clara Zheng | Medium
June 2, 2024 - ... name = "Isaac" age = 18 print("My name is {}, and I am {} years old.".format(name, age)) # Outputs: My name is Isaac, and I am 18 years old. ... name = "Isaac" age = 18 print(f"My name is {name}, and I am {age} years old.") # Outputs: My ...
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-print-function
Python Print() Function: How to use Print Statement with Examples | DataCamp
February 28, 2020 - However, unlike the format function ... ... Let's see what happens if you specify %s for the variable a which is an integer. print("%s is an integer while %s is a string."%(a,b)) ... As you can see from the above example, it still works....