条件处理范围中的最后一项

时间:2014-04-30 15:45:15

标签: python range

我正在尝试根据我们在某个范围中的最后一项时间进行条件处理,例如:

for i in range(intNumberOfPlayers):            
        #If we are on the last item in the range, do this...

1 个答案:

答案 0 :(得分:1)

for i in range(intNumberOfPlayers):
    if i == intNumberOfPlayers - 1:
        print(i) #print last item

范围不包括在内,因此最后一项是intNumberOfPlayers - 1