- 1

i dont get the logic on the range function...

i just dont get it,they say it stops b4 the specified no or sumn , basically i dont get it

9th Sep 2022, 12:49 PM
Roy derell
Roy derell - avatar
3 Antworten
+ 3
Range(10) does not include 10 but 0 to 9. But.... 10 steps are done. Range(2,6) does not include 6, but 6-2 steps are done. range(len(alist)) iterates all indicees of alist. It might be strange for newbies, but for the most common use cases of range, it is very useful.
9th Sep 2022, 1:52 PM
Oma Falk
Oma Falk - avatar
+ 1
Let me explain, in python it depends of how you use it, if you just use range(6) it will do 6 steps before stopping if you are putting other parameters like (2,6) it will start from the value of 2 and stop at the value of 5 because it has default the step value of 1 it is like puttin '<' in other programming languages like for(int i=2;i<6;i++), you can put the third paramter that represent the step (2,8,2) and it will go like: 2 4 6
9th Sep 2022, 1:44 PM
Ionuț-Alexandru Sbaroi
Ionuț-Alexandru Sbaroi - avatar