This question already has an answer here:
I have any string. like 'buffalo',
x='buffalo'
I want to convert this string to some variable name like,
buffalo=4
not only this example, I want to convert any input string to some variable name. How should I do that (in python)?
After that you can check it by:
As an output you will see:
2
You can use a Dictionary to keep track of the keys and values.
For instance...
A dictionary is very similar to a real life dictionary. You have a word and you have a definition. You can look up the word and get the definition. So in this case, you have the word "Buffalo" and it's definition is 4. It can work with any other word and definition. Just make sure you put them into the dictionary first.
This is the best way, I know of to create dynamic variables in python.
I found a similar, but not the same question here Creating dynamically named variables from user input
[Editted according to Martijn's suggestion]