use variable in a string python code example
Example 1: how to use a string variable as a variable name in python
name = 'varname'
value = 'something'
setattr(self, name, value)
print (self.varname)
Example 2: how to use variables in string in python
x = 2
y = f'This is a string using variable x: {x}'
print(y)
Example 3: how to create a variable in python
variable1 = "value"
variable2 = 1000000
variable3 = 10000.0
variable4 = True
Example 4: embed variables python
print('Hi, my name is {name} and my age is {age}'.format(**locals()))
print('Hi, my name is {name} and my age is {age}')