Ok...so, it's kind of easy.

The old method:

num = 6
mystr = 'number is %s' % num
print(mystr) # number is 6

The newer .format method:

num = 6
mystr = "number is {}".format(num)
print(mystr) # number is 6

The .format method using named variable (useful for when sequence can't be depended upon):

num = 6
mystr = "number is {num}".format(num=num)
print(mystr) # number is 6

The shorter f-string method: (thank you @mayur)

num = 6
mystr = f"number is {num}"
print(mystr) # number is 6
Answer from skeetastax on Stack Overflow
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ string-interpolation
Python String Interpolation
... String interpolation is a process substituting values of variables into placeholders in a string. For instance, if you have a template for saying hello to a person like "Hello {Name of person}, nice to meet you!", you would like to replace the placeholder for name of person with an actual name.
๐ŸŒ
Python
peps.python.org โ€บ pep-0498
PEP 498 โ€“ Literal String Interpolation | peps.python.org
Because the compiler must be involved in evaluating the expressions contained in the interpolated strings, there must be some way to denote to the compiler which strings should be evaluated. This PEP chose a leading 'f' character preceding the string literal.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-string-interpolation
Python String Interpolation: A Beginner's Guide | DataCamp
February 13, 2025 - In this code, the output_string variable is assigned an f-string. The f prefix before the opening quote indicates that the string supports embedded expressions. The variable name is evaluated and its value is inserted into the string, resulting in the output: "My name is Mark." Not only variable values, but also calculations or expressions may be inserted into f-strings. Consider this example. import math a = 3.0 b = 4.0 # Use string interpolation for the formula print(f'The hypotenuse of a triangle with base {a} and side {b} is {math.sqrt(a ** 2 + b ** 2)}.')
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string-interpolation
Python String Interpolation - GeeksforGeeks
July 12, 2025 - Let's consider an example to understand it better, suppose you want to change the value of the string every time you print the string like you want to print "hello <name> welcome to geeks for geeks" where the <name> is the placeholder for the name of the user. Instead of creating a new string every time, string interpolation in Python can help you to change the placeholder with the name of the user dynamically.
๐ŸŒ
Real Python
realpython.com โ€บ python-string-interpolation
String Interpolation in Python: Exploring Available Tools โ€“ Real Python
July 5, 2024 - But the story doesnโ€™t end with the modulo operator. Later, Python introduced the str.format() method: ... The method interpolates its arguments into the target string using replacement fields limited by curly brackets.
๐ŸŒ
Medium
martinezjf2.medium.com โ€บ learn-concatenation-and-interpolation-with-python-strings-2adbe04ce1a0
Learn Concatenation and Interpolation with Python Strings | by Jeffrey Martinez | Medium
December 15, 2021 - In order for us to string interpolate, we have to use an f string whose syntax is as follows: f" {} " where anything inside the curly bracket would be a variable you would like to use.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ string-interpolation-python
Python String Interpolation: 4 Methods (with Code)
November 10, 2023 - String interpolation is a powerful feature in Python that allows for the dynamic insertion of variables into strings. It enhances code readability, simplifies string formatting, and provides flexibility in generating output.
Find elsewhere
๐ŸŒ
Linode
linode.com โ€บ docs โ€บ guides โ€บ python-string-interpolation
An Introduction to Python String Interpolation | Linode Docs
May 20, 2022 - During string interpolation a string literal is evaluated and if any placeholders are present, they are substituted by the indicated variable values. String interpolation helps reduce repetition in code and allows for dynamic string substitution.
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ interpolating-variables-string
Interpolating Variables Into a String (Video) โ€“ Real Python
Back here in a REPL, Iโ€™ll have you try out variable interpolation. You can specify a variableโ€™s name directly in an f-string literal, and Python will replace the name with its corresponding value.
Published ย  October 1, 2019
๐ŸŒ
Python Central
pythoncentral.io โ€บ python-string-interpolation-a-comprehensive-guide
Python String Interpolation: A Comprehensive Guide | Python Central
March 1, 2024 - Using the f string is the most straightforward and simple way to interpolate strings. If you're wondering why it's called an f string, it's because the letter f is placed before the quotes. This method was introduced to Python after version 3.6, allowing you to insert expressions, variables, and function calls between curly braces directly.
๐ŸŒ
Python
peps.python.org โ€บ pep-0215
PEP 215 โ€“ String Interpolation - Python Enhancement Proposals
July 24, 2000 - As described here (a string prefix rather than an operator), it introduces no new security issues since the expressions to be evaluated must be literally present in the code. The Itpl module at [1] provides a prototype of this feature. It uses the tokenize module to find the end of an expression to be interpolated, then calls eval() on the expression each time a value is needed.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python string interpolation
String Interpolation in Python | Delft Stack
November 20, 2023 - Using string interpolation, one can dynamically insert values inside a string. In Python, there are four ways in which we can perform string interpolation, namely, modulo (%), format() method, formatted strings, and template class.
๐ŸŒ
pypyr
pypyr.io โ€บ docs โ€บ substitutions โ€บ format-string
Format string interpolation expressions in the pypyr task-runner.
May 26, 2024 - You can use substitution tokens, aka string interpolation, to format strings where specified for context items. This substitutes anything between {curly braces} with the context value for that key.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-f-strings-literal-string-interpolation
Python f-strings - PEP 498 - Literal String Interpolation | DigitalOcean
August 3, 2022 - Python f-strings or formatted strings are the new way to format strings. This feature was introduced in Python 3.6 under PEP-498. Itโ€™s also called literal string interpolation.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ python-string-interpolation-with-the-percent-operator
Python String Interpolation with the Percent (%) Operator
August 24, 2023 - These %s strings are actually placeholders in our "template" string, and they indicate that strings will be placed there. As a first example, below we demonstrate using the Python REPL how to print a string value and a float value:
๐ŸŒ
University of Toronto
teach.cs.toronto.edu โ€บ ~csc110y โ€บ fall โ€บ notes โ€บ 12-interlude-nifty-python-features โ€บ 02-string-interpolation.html
12.2 String Interpolation with f-strings
Okay, so whatโ€™s the point? There is one key difference between string literals and f-strings: in an f-string, any text surrounded by curly braces ({...}) is interpreted as a Python expression, which is evaluated, converted into a string, and then inserted back into the literal.