Python声明多个列表 [英] Python declare multiple lists
本文介绍了Python声明多个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在列表中有300多个变量,我必须列出每个变量:
I have more than 300 variables in a list and i have to make a list of each variables:
示例:
x=['aze','qsd','frz']...
我要
MAXaze=[]
MAXqsd=[]
MAXfrz=[]
...
无需输入
感谢您的帮助
推荐答案
您可以使用字典来存储值:
You can use a dictionary to store the values:
x=['aze','qsd','frz',...]
vars = {}
for i in x:
vars["MAX" + i] = []
或者为了使它们成为真实变量,可以将它们添加到全局变量中:
Or in order for them to become real variables you can add them to globals:
x=['aze','qsd','frz',...]
for i in x:
globals()["MAX" + i] = []
您现在可以使用:
MAXaze = [1,2,3]
这篇关于Python声明多个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文