What role does the following line of code play in for loops? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What role does the following line of code play in for loops?

What role does the following line of code play in for loops? max_index = len(words) - 1

20th May 2020, 5:28 PM
Rik Gart
2 Answers
+ 2
Please show more context, as this simply assigns the value equal to length of the words object minus 1 to a variable named max_index.
20th May 2020, 5:32 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Rik Gart This line make for loop to go upto the end element in a array because array index starts with 0 and its sizs start with 1 which is always greter than its index so we decrease it by one to reach to end elemnt of an array
20th May 2020, 5:53 PM
Abhay
Abhay - avatar