String interpolation is a process of substituting values of local variables into placeholders in a string.

It is implemented in many programming languages such as Scala:

//Scala 2.10+
var name = "John";
println(s"My name is $name")
>>> My name is John

Perl:

my $name = "John";
print "My name is $name";
>>> My name is John

CoffeeScript:

name = "John"
console.log "My name is #{name}"
>>> My name is John

and many others.

On the first sight, it doesn’t seem that it’s possible to use string interpolation in Python. However, we can implement it with just 2 lines of Python code.

Continue reading