Answer the question
In order to leave comments, you need to log in
How do F strings in a variable work correctly?
Hello.
I have a line string1 = '{title} added. Which add more?'
It is stored in the database.
How can I make the string1 F variable a string so that the title variable will work?
I tried like this
string1 = '{title} added. Which add more?'
title = 'blabla'
print(f'{string1}')
Answer the question
In order to leave comments, you need to log in
>>> def makef(nonf: str) -> str:
... return eval(f'f"{nonf}"')
...
>>> title = 'name'
>>> s = 'some {title}'
>>> print(makef(s))
some name
>>> title = "asd"
>>> string1 = f'{title} added. Which add more?'
>>> print(string1)
asd added. Which add more?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question