Python 3.6 will add literal string interpolation similar to Ruby's string interpolation. Starting with that version of Python (which is scheduled to be released by the end of 2016), you will be able to include expressions in "f-strings", e.g.

name = "Spongebob Squarepants"
print(f"Who lives in a Pineapple under the sea? {name}.")

Prior to 3.6, the closest you can get to this is

name = "Spongebob Squarepants"
print("Who lives in a Pineapple under the sea? %(name)s." % locals())

The % operator can be used for string interpolation in Python. The first operand is the string to be interpolated, the second can have different types including a "mapping", mapping field names to the values to be interpolated. Here I used the dictionary of local variables locals() to map the field name name to its value as a local variable.

The same code using the .format() method of recent Python versions would look like this:

name = "Spongebob Squarepants"
print("Who lives in a Pineapple under the sea? {name!s}.".format(**locals()))

There is also the string.Template class:

tmpl = string.Template("Who lives in a Pineapple under the sea? $name.")
print(tmpl.substitute(name="Spongebob Squarepants"))
Answer from Sven Marnach on Stack Overflow
๐ŸŒ
Python
peps.python.org โ€บ pep-0498
PEP 498 โ€“ Literal String Interpolation | peps.python.org
A single closing curly brace '}' in the literal portion of a string is an error: literal closing curly braces must be doubled '}}' in order to represent a single closing brace. The parts of the f-string outside of braces are literal strings.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ string-interpolation
Python String Interpolation
In above example literal prefix f tells Python to restore the value of two string variable name and program inside braces {}. So, that when we print we get the above output. This new string interpolation is powerful as we can embed arbitrary Python expressions we can even do inline arithmetic ...
๐ŸŒ
Real Python
realpython.com โ€บ python-f-strings
Python's F-String for String Interpolation and Formatting โ€“ Real Python
November 30, 2024 - An f-string in Python is a string ... {}. To include dynamic content in an f-string, place your expression or variable inside the braces to interpolate its value into the string....
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string-interpolation
Python String Interpolation - GeeksforGeeks
July 12, 2025 - Note: To know more about str.format(), refer to format() function in Python ยท PEP 498 introduced a new string formatting mechanism known as Literal String Interpolation or more commonly as F-strings (because of the leading f character preceding the string literal).
๐ŸŒ
Real Python
realpython.com โ€บ python-string-formatting
Python String Formatting: Available Tools and Their Features โ€“ Real Python
December 2, 2024 - Formatted string literals are a Python parser feature that converts f-strings into a series of string constants and expressions. These are then joined up to build the final string.
๐ŸŒ
Python
peps.python.org โ€บ pep-0536
PEP 536 โ€“ Final Grammar for Literal String Interpolation | peps.python.org
PEP 498 introduced Literal String Interpolation (or โ€œf-stringsโ€). The expression portions of those literals however are subject to certain restrictions. This PEP proposes a formal grammar lifting those restrictions, promoting โ€œf-stringsโ€ ...
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.
๐ŸŒ
Python
peps.python.org โ€บ pep-0502
PEP 502 โ€“ String Interpolation - Extended Discussion | peps.python.org
August 10, 2015 - >>> location = 'World' >>> f'Hello, {location} !' # new prefix: f'' 'Hello, World !' # interpolated result ยท PEP 498 โ€“ Literal String Formatting, delves into the mechanics and implementation of this design.
๐ŸŒ
Python Central
pythoncentral.io โ€บ python-string-interpolation-a-comprehensive-guide
Python String Interpolation: A Comprehensive Guide | Python Central
March 1, 2024 - Interpolating strings in Python involves the string temple and the value (or set of values) that belong inside the template. For the feature to work, the Python compiler must determine where to place the values inside the template.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ String_interpolation
String interpolation - Wikipedia
1 week ago - Python supports string interpolation as of version 3.6, referred to as "formatted string literals" or "f-strings".
๐ŸŒ
Real Python
realpython.com โ€บ python-string-interpolation
String Interpolation in Python: Exploring Available Tools โ€“ Real Python
July 5, 2024 - In this example, you have two variables, x and y. Then, you create an f-string literal with three replacement fields. The first two fields hold the variables, and the third field holds an expression. Itโ€™s important to note that Python evaluates f-strings at runtime. So, in this example, x, y, and x + y are evaluated and interpolated into the string literal when Python runs the line of code containing the f-string.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ string.templatelib.html
string.templatelib โ€” Support for template string literals
Unlike f-strings, where format specifications are applied automatically via the format() protocol, the expected behavior with t-strings is that code that processes the interpolation will decide how to interpret and whether to apply the format specification. As a result, format_spec values in interpolations can be arbitrary strings, including those that do not conform to the format() protocol. ... __new__(value: object, expression: str, conversion: Literal['a', 'r', 's'] | None = None, format_spec: str = '')ยถ
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-string-interpolation
Python String Interpolation: A Beginner's Guide | DataCamp
February 13, 2025 - There are several different string interpolation techniques available in Python. The most commonly recommended method is formatted string literals, also known as f-strings, which have been available since Python 3.6.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is python string interpolation?
What is Python String Interpolation? | Scaler Topics
April 12, 2024 - Python 3.6 introduced a new Python string interpolation technique known as the literal string interpolation, as well as a new literal prefix f. This new string formatting method is both potent and simple to use.
๐ŸŒ
Python
peps.python.org โ€บ pep-0750
PEP 750 โ€“ Template Strings - Python Enhancement Proposals
July 8, 2024 - Like Template, it is a new class found in the string.templatelib module: class Interpolation: value: object expression: str conversion: Literal["a", "r", "s"] | None format_spec: str __match_args__ = ("value", "expression", "conversion", "format_spec") def __new__( cls, value: object, expression: str = "", conversion: Literal["a", "r", "s"] | None = None, format_spec: str = "", ): ...
๐ŸŒ
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.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 10 python string interpolation approaches
Python String Interpolation: Enhancing Code Readability
May 21, 2024 - So in this article, you will get understanding of Python String Interpolation its basics and also it help you to learn different approaches. ... String interpolation is the process of embedding expressions or variables within a string literal.
๐ŸŒ
Python
peps.python.org โ€บ pep-0501
PEP 501 โ€“ General purpose template literal strings | peps.python.org
August 8, 2015 - This PEP complements the literal string typing support added to Pythonโ€™s formal type system in PEP 675 by introducing a safe way to do dynamic interpolation of runtime values into security sensitive strings.