- 2
Can someone explain to me ? for index in range(len(meal)-1-,1,-1):
2 Respostas
+ 1
for example ,
meal="Burger"
so the length of meal is 6.
now for(index in range (len(meal)-1,1,-1): means:
for (index in range (5,1,-1) [here len(meal)=6,so len(meal)-1=5]
so the loop will stop when index becomes 1,means the loop will run 4 times.
0
range is like the following:
range(from, to, step)
, so index will be from len(meal)-1 to 1 by -1
eg. meal = "pizza"
index will be:
from len("pizza")-1 #5-1 = 4
to 1
by -1
(index in (4, 3, 2))