+ 2

Range

Why the number 10 wasn't appearing? numbers.range(10) print(numbers) output will be 0 - 9 is it just count 0 as one?

12th Apr 2018, 1:15 AM
Medo Hamdani
Medo Hamdani - avatar
3 odpowiedzi
+ 6
Just in math it is useful to cancatenating half-ranges. Half-ranges mean that lower number in notation IS IN range, but larger IS NOT. range(10) ==> [0; 10) // including 0, excluding 10 Union for half-ranges that have end on the same number has next property: each number in result repeats once. But so can't be archived in usual ranges. Compare: [0; 5) U [5; 10) = [0; 10) (0,1,2,3,4) U (5,6,7,8,9) = (0,1,2,3,4,5,6,7,8,9) And [0; 5] U [5; 10] = [0; 10] but '5' appears twice
12th Apr 2018, 1:34 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 5
Also, length of half-range is easy to count. Just find difference between begin and end of half-range
12th Apr 2018, 1:37 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 3
range(10) means one number less i mean range(5) will print 0 to 4 etc.
12th Apr 2018, 1:19 AM
Raj Chhatrala
Raj Chhatrala - avatar