#works only inside classes
name = 'varname'
value = 'something'
setattr(self, name, value) #equivalent to: self.varname= 'something'
print (self.varname)
#will print 'something'
>>> foo = "bar"
>>> exec(foo + " = 'something else'")
>>> print bar
something else
>>>
>>> foo = dict()
>>> f'{foo=}'.split('=')[0]
'foo'