如何將變數值插入字串python?我需要在 html 文本中向 {g} 插入“g”值。

嘗試了 f 字串,它不起作用
uj5u.com熱心網友回復:
您可以使用str.format{g}在示例中插入值
g = 234
text = '''
<p>Hi {g}!</p>
'''
print(text.format(g=g))
uj5u.com熱心網友回復:
使用字串替換,但這不是超級保存...
htmlmsg.replace('{g}', str(g))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/452322.html
上一篇:我將如何回傳此功能?
