Every example I have seen of Python string variable interpolation uses the print function.
For example:
num = 6
# str.format method
print("number is {}".format(num))
# % placeholders
print("number is %s"%(num))
# named .format method
print("number is {num}".format(num=num))
Can you interpolate variables into strings without using print?
Ok...so, it's kind of easy.
The old method:
The newer
.formatmethod:The
.formatmethod using named variable (useful for when sequence can't be depended upon):The shorter
f-stringmethod: (thank you @mayur)