what is max_index | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what is max_index

words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1 max_index = len(words) - 1 here what does max index means ? what is max index... how that works or this is a string

10th Feb 2017, 4:37 PM
Khan Asfi Reza Pranto
Khan Asfi Reza Pranto - avatar
2 Answers
+ 4
max_index is a variable. You take the length of the list, and minus one to account for the habit of programming languages to start counting from 0. The while statement then takes this number, and counts up to it, effectively printing all the items in the list. tldr; It's nothing special, just an int. that is equel to the list length minus one.
10th Feb 2017, 10:13 PM
Lelearner
+ 2
"max_index" is a variable used as limit of iterations. The loop will be performed UNTIL variable "counter" matches with variable "max_index".
25th Feb 2017, 1:13 AM
Khameir Sarin
Khameir Sarin - avatar