How to Insert variable value to string python? I need to insert 'g' value to {g} in html text.
tried f string and it doesn't work
CodePudding user response:
You can use str.format to insert value into {g}
in your example
g = 234
text = '''
<p>Hi {g}!</p>
'''
print(text.format(g=g))
CodePudding user response:
Using string replacement, but this is not super save...
htmlmsg.replace('{g}', str(g))