我有一张单子,我把单子变成了字符串。现在我想通过使用字符串格式将1附加到变量的末尾,为列表中的每个项分配一个变量。你知道吗
listOne = ['33.325556', '59.8149016457', '51.1289412359']
itemsInListOne = int(len(listOne))
num = 4
varIncrement = 0
while itemsInListOne < num:
for i in listOne:
print a = ('%dfinalCoords{0}') % (varIncrement+1)
print (str(listOne).strip('[]'))
break
我得到以下错误:语法错误:无效语法
如何修复此问题并以以下格式分配新变量:
a0=33.325556 a1=59.8149016457等
您当前的代码有几个问题:
有一句话给你带来了麻烦:
这是:
print
和赋值a =
(因此SyntaxError
)'%d'
和'{0}'
);以及varIncrement
,所以无论如何,你总是会得到'1finalCoords{0}'
。你知道吗我建议如下:
您可以通过索引轻松地访问或编辑单个值,例如
看看你的previous question,似乎你可能想要两个列表中的坐标对,这也可以通过一个简单的2元组列表来实现:
它给出:
相关问题 更多 >
编程相关推荐