0

why is nums = list(range (5,8) print (Len(nums)) = 3 isn't 4?

4th Jul 2016, 7:48 PM
Andres Eloy Lozada Molinett
Andres Eloy Lozada Molinett - avatar
13 ответов
+ 6
It's 3 because your asking for a list with a range from 5-8. Remember that with a list [0] is really the first thing in the list. Try printing 'nums' and you will see the list: [5, 6, 7] Your brain wants to think that it's 6, 7, 8 though. Either way, the length between 5 and 8 is three numbers.
4th Jul 2016, 8:07 PM
Dean
+ 3
in range(a, b) b is not counted by python soin range(5, 8) elements will be 5, 6, 7 so len is 3
5th Jul 2016, 6:44 AM
pulkit29
pulkit29 - avatar
+ 1
3
26th Nov 2019, 2:05 AM
MP On
MP On - avatar
0
yup. when it's range (1, 5) it will not count the top number, or 5 in this case.
4th Jul 2016, 8:11 PM
Rob Jones
Rob Jones - avatar
0
thanks for answering appreciated
4th Jul 2016, 8:25 PM
Andres Eloy Lozada Molinett
Andres Eloy Lozada Molinett - avatar
0
see when the range is 1 to 5 then the IDLE shows numbers upto 5 which are 1,2,3,4
5th Jul 2016, 3:51 AM
Tanvir
Tanvir - avatar
0
5
24th Jan 2020, 6:14 AM
sasirekha.k
0
The ans is 3
29th Jun 2020, 2:56 PM
Faith Mundi
Faith Mundi - avatar
0
And:3
15th Sep 2020, 8:52 AM
Saran M
Saran M - avatar
0
the answer is 3
29th Dec 2020, 1:32 PM
Coder Ayush
Coder Ayush - avatar
0
3
12th May 2021, 6:04 AM
Sangeetha Geetha
Sangeetha Geetha - avatar
0
len is 3
24th May 2021, 9:49 AM
Hayder Jawad Al-ATBEE
Hayder Jawad Al-ATBEE - avatar
0
3
11th Jul 2022, 6:28 PM
Mohammadreza Mostafavi