can I use a variable's value as a new variable? How I can do that?
a = "rajiv"
I want to set rajiv to another value a = "1"
but I get a's value as 1 and not rajiv's
can I use a variable's value as a new variable? How I can do that?
a = "rajiv"
I want to set rajiv to another value a = "1"
but I get a's value as 1 and not rajiv's
You could use globals()
>>> a = 'rajiv'
>>> globals()[a] = 1
>>> rajiv
1
You can use globals()
like the others have suggested.
However, it is thought to be bad practice
I say utilize object in python
obj = {}
obj['a'] = 'foobar'
obj[obj['a']] = 'hello'
print(obj) # {'a': 'foobar', 'foobar': 'hello world'}