Вопрос

I am trying to do conditional processing according to when we are at the last item in a range, for example:

for i in range(intNumberOfPlayers):            
        #If we are on the last item in the range, do this...
Это было полезно?

Решение

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

Ranges are not inclusive, so the last item is intNumberOfPlayers - 1

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top