Python 生成动态变量 调用动态变量

动态生成变量:

variable = locals()
for i in range(10):
    variable['A'+str(i)] = 123
print(A8)

调用动态变量:

v = locals()
lst1 = range(10)

for i in lst1:
    v['A'+ str(i+1)] = [1,2,3]

print(A1)
d = v.copy()
for var in d:
    if "A" in var and "__" not in var:
        print(eval(var)[2])

 

posted @ 2018-05-16 22:16  VVVinson  阅读(2481)  评论(0编辑  收藏  举报