I would like to input variables names and have them converted to actual variables, similar to what you can do with print statements. Is this possibe?
print(f'I love {fruit} and the colour {colour}')
Code:
fruit=apples
colour=red
message=input('Enter your message: ')
print(message)
Desired input:
Enter your message: I love {fruit} and the colour {colour}
Desired Output:
I love apples and the colour red
Solution: How can i use f-string with a variable, not with a string literal?
variables = {
'fruit': 'apples',
'colour': 'red'
}
message=input('Enter your message: ').format(**variables)
print(message)
Input: I love {fruit} and the colour {colour}
Output: I love apples and the colour red