Frage

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...
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top