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
Post a Comment