For example
i='a'
b='b'
i+b='dog'
print (ab)
Expected result: 'dog'
received result: 'Error: can't assign to operator"
For example
i='a'
b='b'
i+b='dog'
print (ab)
Expected result: 'dog'
received result: 'Error: can't assign to operator"
Though it's not recommended to do, you can update globals
:
i='a'
b='b'
globals()[i+b] = 'dog'
print (ab) # 'dog'
Another (not recommended) way of achieving the same result is using exec
:
exec "ab = 'dog'"
print ab
A better way to achieve dynamically changing key-value pairs can be achieved by using a dictionary:
mapper = {}
mapper[i+b] = 'dog'
print mapper['ab'] # 'dog'
>>> i='a'
>>> b='b'
>>> locals()[i+b] = 'dog'
>>> print(ab)
dog
I ... uhh ... hope this helps.