Question: How do I transform a classic string to an f-string?

```
variable = 42
user_input = "The answer is {variable}"
print(user_input)

```

Output: `The answer is {variable}`

```
f_user_input = # Here the operation to go from a string to an f-string
print(f_user_input)

```

Desired output: `The answer is 42`

Answer: 
The real answer is probably: don't do this. By treating user input as an f-string, you are treating it like code which creates a security risk. You have to be really certain you can trust the source of the input.

If you are in situation where you know the user input can be trusted, you can do this with [eval()](https://docs.python.org/3/library/functions.html#eval):

```
variable = 42
user_input="The answer is {variable}"
eval("f'{}'".format(user_input))
'The answer is 42'

```

Edited to add: @wjandrea pointed out [another answer](https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string/47599254#47599254) which expands on this.
You can use f-string instead of normal string.

```
variable = 42
user_input = f"The answer is {variable}"
print(user_input) 

```