+ 1

Why itā€™s not getting into for loop,plz help

s="malayalam" for i in range(len(s)-1,0): print(i)

30th May 2022, 1:15 PM
Pramod
6 Answers
+ 6
You missed the "step" argument in range. By default it is 1. So you need range(len(s)-1, 0, -1)
30th May 2022, 1:22 PM
Lisa
Lisa - avatar
+ 4
range goes [start; stop) The stop is not included 8n the sequence. To get 0, you would need to write: range(len(s) - 1, -1, -1)
30th May 2022, 2:26 PM
Lisa
Lisa - avatar
+ 1
Pramod You cannot do like in Java because in python there is no semicolon so doing like this: for i = 0 i < 10 will give syntax error
30th May 2022, 3:02 PM
AĶ¢J
AĶ¢J - avatar
0
Thank you Lisa u made my day new to python ,even small things are getting complex Thanks again
30th May 2022, 2:12 PM
Pramod
0
Lisa why for i in range(len(s)-1,0,-1) Why does the loop doesnt consider zero it stops at 1 In Java for(int i=8;i>=0;iā€”) here it goes till 0 no issues why not in python
30th May 2022, 2:23 PM
Pramod
0
Other than using range can u please suggest a for loop in python as simple as in Java like this for(int i=0;i<=10;i++) Without using that range function and all
30th May 2022, 2:27 PM
Pramod