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

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -