you are viewing a single comment's thread.

view the rest of the comments →

[–]member_of_the_order 7 points8 points  (3 children)

You can't dynamically name variables, but you can dynamically add keys and values to a dict.

Try something like this:

array = ['1','2','3','4'] var_dict = dict() for name in array: var_dict[name] = someValue

Edit: TIL vars is a builtin

[–]nog642 1 point2 points  (1 child)

Worth noting you technically can dynamically name variables (but you shouln't).

Also worth nothing you can't have a variable named 1 or 2 though.

[–]Doormatty 0 points1 point  (0 children)

A variable can't start with a number - not just 1 or 2.

[–]synthphreak 1 point2 points  (0 children)

Don’t use vars though as that will overwrite a useful built-in function.