I have a string that a user entered s = "my name is {name} and my age is {age}"
and I am trying to have {name}
and {age}
replaced by other strings.
In the case of a single variable name="bob"
, using .replace('{name}', 'bob')
would be simple if it was only {name}
, but I am aiming to have around 10-15 different variables, which would complicate things.
The variable could be at any position in the string, I am also getting the string from a database d = {'name': 'bob', 'age': 18}
, so f-strings can't be used.