python批量赋值操作

变量名和变量值俊发生规律的变化,利用for循环完成赋值操作,举个例子:

for i in range(1, 10):
    exec("t%d=i"%i)

print(t1)
print(t2)
print(t3)
print(t4)
print(t5)
print(t6)
print(t7)
print(t8)
print(t9)

执行结果:

1
2
3
4
5
6
7
8
9

利用python中的exec()函数来完成,

转载自:https://blog.csdn.net/c2366994582/article/details/80181847

You may also like...