Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If 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



Wait, why would range(3) start at 0 and not 1 in a 1-based language?


You said: "I don't understand why 0 ≤ i ≤ N wouldn't have worked instead". Was that a typo? Did you mean 0 < i ≤ N?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: