سؤال

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