get variables with string

linkaiyi
Follow

There are multiple ways to do so.

Using vars():
>>> a = ['a', 'b', 'c']
>>> vars()[a[0]] = 5
>>> a
5
Using exec():
>>> exec("b=5")
>>> b
5
Object has 0 attachments

Was this article helpful?

This article is viewed 40 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support