python - How do I create a variable number of variables? -


how accomplish variable variables in python?

here elaborative manual entry, instance: variable variables

i have heard bad idea in general though, , security hole in python. true?

use dictionaries accomplish this. dictionaries stores of keys , values.

>>> dct = {'x': 1, 'y': 2, 'z': 3} >>> dct {'y': 2, 'x': 1, 'z': 3} >>> dct["y"] 2 

you can use variable key names achieve effect of variable variables without security risk.

>>> x = "spam" >>> z = {x: "eggs"} >>> z["spam"] 'eggs' 

make sense?


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -