0

How to Insert variable value to string python? I need to insert 'g' value to {g} in html text. code

tried f string and it doesn't work

1 Answer 1

1

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.