max_index=len(words)-1 can someone explain that part for me? | Sololearn: Learn to code for FREE!
Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję
0

max_index=len(words)-1 can someone explain that part for me?

17th Jul 2016, 4:50 PM
LaPerro Mouse
LaPerro Mouse - avatar
2 odpowiedzi
+ 1
max_index = len(words)-1 let's split up this statement 'max_index' is the variable u declare in that variable u are calling a default function 'len()' the purpose of len function is to return the length of the passed argument for example len('hello') would return 5 since 'hello' contains five characters. so now coming back to question. the len() has a variable as an argument. this variable might be declared but u missed it let's take it as words='sample' len(words) is 6 and a '-1' is given at end 'max_index' now stores the answer '5' Hope you got it
17th Jul 2016, 5:09 PM
sundar
sundar - avatar
- 1
laPerro answer well but in short the variable max_index will store 5
19th Jul 2016, 5:07 AM
Bonimwat Optimux Vicker
Bonimwat Optimux Vicker - avatar