+ 1

Use of range(n, n+1) in Python

Do we need to use the range(n, n + 1) only with factorials or can be used with other kind of purpose? Example of my code: https://code.sololearn.com/cwZyW1yDa67n/?ref=app Thank you in advance.

2nd Jul 2020, 7:07 PM
Whally O.
Whally O. - avatar
7 Answers
+ 4
Python `range` function includes the first argument given, but the function excludes the second argument given. So, taking for example `range(<from>, <to>)`, <from> is the beginning, whereas <to> minus 1 is the end. range(1, 10) # 1 up to 9 Doing `range(<from>, <to> + 1)` means the range will begin with <from> and ends by <to> inclusively. range(1, 10 + 1) # 1 up to 10
2nd Jul 2020, 7:55 PM
Ipang
+ 3
It's why there is such a community Maybe one day you help me out Who knows right? 😁
2nd Jul 2020, 8:26 PM
Ipang
+ 2
Excelente, Ipang, now is more clear that range (n, n + 1) for me, very simple and powerful explanation, Thanks, gracias
2nd Jul 2020, 8:22 PM
Whally O.
Whally O. - avatar
+ 2
Ipang don't worry, I'll keep looking for your help 😾
2nd Jul 2020, 8:24 PM
Whally O.
Whally O. - avatar
+ 2
That's right, absolutely, indeed!
2nd Jul 2020, 8:37 PM
Whally O.
Whally O. - avatar
3rd Jul 2020, 6:25 PM
Muhammadjon Latifov
Muhammadjon Latifov - avatar
+ 1
De nada Whally O 👌
2nd Jul 2020, 8:23 PM
Ipang