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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -