3 ms·
That would give a sequence of N+1 elements, though. Confusing if you had a function like range(N), for example.
by weavejester 4y ago
That would give a sequence of N+1 elements, though. Confusing if you had a function like range(N), for example.
- goatlover 4y agoWhy, it would be an inclusive instead of exclusive range. N is the last element, so no reason for N+1.
- weavejester 4y agoIf we use inclusive ranges where 0 ≤ i ≤ N, then len(range(N)) == N+1. e.g. len(range(3)) == len([0, 1, 2, 3]) == 4
- goatlover 4y agoWait, why would range(3) start at 0 and not 1 in a 1-based language?
- weavejester 4y agoYou said: "I don't understand why 0 ≤ i ≤ N wouldn't have worked instead". Was that a typo? Did you mean 0 < i ≤ N?