2017-02-09 189 views
-1

目前,我有这个代码写在声明蟒蛇10个变量:声明多个变量的for循环蟒蛇

oneScore = textFont.render('1. ' + str(sortedList[0][0]) + ' ' + str(sortedList[0][1]), True, white) 
twoScore = textFont.render('2. ' + str(sortedList[1][0]) + ' ' + str(sortedList[1][1]), True, white) 
threeScore = textFont.render('3. ' + str(sortedList[2][0]) + ' ' + str(sortedList[2][1]), True, white) 
fourScore = textFont.render('4. ' + str(sortedList[3][0]) + ' ' + str(sortedList[3][1]), True, white) 
fiveScore = textFont.render('5. ' + str(sortedList[4][0]) + ' ' + str(sortedList[4][1]), True, white) 
sixScore = textFont.render('6. ' + str(sortedList[5][0]) + ' ' + str(sortedList[5][1]), True, white) 
sevenScore = textFont.render('7. ' + str(sortedList[6][0]) + ' ' + str(sortedList[6][1]), True, white) 
eightScore = textFont.render('8. ' + str(sortedList[7][0]) + ' ' + str(sortedList[7][1]), True, white) 
nineScore = textFont.render('9. ' + str(sortedList[8][0]) + ' ' + str(sortedList[8][1]), True, white) 
tenScore = textFont.render('10. ' + str(sortedList[9][0]) + ' ' + str(sortedList[9][1]), True, white) 

是否有这样做的更有效的方法?

+0

他们需要以变量的形式吗?你可以把它们放在字典中吗?编辑:或任何其他序列类型 –

+0

这是我的宠物,但* Python没有变量声明*。 –

回答

1

不带有命名变量。这就是列表

score[i] = textFont.render('1. ' + str(sortedList[i][0]) + ' ' + str(sortedList[i][1]), True, white) 
+0

不能相信我没有想到,谢谢。 – Callum