我无法增加列表名中的数字,因为我需要一个从0到24的列表名,我尝试过使用串联,但没有成功
下面是我的示例代码:
d.last0 = [0,0]
d.last1 = [0,0]
d.last2 = [0,0]
d.last3 = [0,0]
d.last4 = [0,0]
.
.
d.last24 = [0,0]
如您所见,这种初始化一直持续到24小时,我想做的是将其循环,以便使代码更快、更高效,但当我将其称为
d["last_{i}"]
它没有返回任何数据,也尝试了以下方法:
d["last{i]".GetValue]
Tags:
使用以下字典代码以满足您的要求
一种方法是使用哈希表(字典)。这些允许您使用密钥并将数据与该密钥关联。以下是使用python词典解决的问题:
如果您坚持使用25个不同的变量,可以在python中使用globals()关键字,您可以这样编辑:
相关问题 更多 >
编程相关推荐