在for循环python中声明多个变量

时间:2017-02-09 21:07:11

标签: python pygame

我目前编写的代码用于在python中声明10个变量:

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)

有更有效的方法吗?

1 个答案:

答案 0 :(得分:1)

不使用命名变量。这就是

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