According to this webarticle: https://www.programiz.com/python-programming/string-interpolation
One can interpolate a variable by using the f
function in combination with the mustache signs {}
. Second one can use the %-formatter
, third one can use the .format() function on an existing string in combination with again the mustache curls {}
and lastly there also exists a Template
class that allows you insert variables in a string like so:
name = 'world'
program ='python'
new = Template('Hello $name! This is $program.')
print(new.substitute(name= name,program=program))
Why so many different methods to do basically the same thing? Is it because most of those methods came with older python versions and are now considered obsolete?
Thank you