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 Overflowpython - How to print formatted string in Python3? - Stack Overflow
What is the function of ':g' in the python f-string?
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.
How to get float to two decimal places without rounding off.
What is the print() function in Python?
Can I format text while using print in Python?
How do I use the Python print statement with variables?
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
You need to apply your formatting to the string, not to the return value of the print() function:
print("So, you're %r old, %r tall and %r heavy." % (
age, height, weight))
Note the position of the ) closing parentheses. If it helps you understand the difference, assign the result of the formatting operation to a variable first:
output = "So, you're %r old, %r tall and %r heavy." % (age, height, weight)
print(output)
You may find it easier to use str.format(), or, if you can upgrade to Python 3.6 or newer, formatted string literals, aka f-strings.
Use f-strings if you just need to format something on the spot to print or create a string for other reasons, str.format() to store the template string for re-use and then interpolate values. Both make it easier to not get confused about where print() starts and ends and where the formatting takes place.
In both f-strings and str.format(), use !r after the field to get the repr() output, just like %r would:
print("So, you're {age!r} old, {height!r} tall and {weight!r} heavy.")
or with a template with positional slots:
template = "So, you're {!r} old, {!r} tall and {!r} heavy."
print(template.format(age, height, weight)