python how to make a string variable code example
Example 1: how to insert a variable into a string without breaking up the string in python
name = "Dan"
age = 21
name_and_age = f"My name is {name}, and I am {age} years old."
print(name_and_age)
Example 2: python get variable from string
some_variable = "here is a string stored in this variable"
print(eval("some_variable"))
import random
thing1 = "thing 1"
thing2 = "thing 2"
thing3 = "thing 3"
number = random.randint(1, 3)
variable_as_a_string = "thing" + str(number)
print(eval(variable_as_a_string))