Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
var_1 = "num_1"
如何将字符串num_1转换为变量名?
num_1
例如,当num_1转换为变量名时,它必须像num_1 = "Some other data"
num_1 = "Some other data"
其他重复的问题和答案对为什么这通常是一个坏主意进行了长时间的讨论。
你确定你不能只使用字典来存储你的值吗?
var_1 = "num_1" myvars = {} # create an empty dictionary myvars[var_1] = 99 print(myvars["num_1"])