[beginner] What's wrong?

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Apr 1 18:57:05 EDT 2016


On 01/04/2016 23:44, sohcahtoa82 at gmail.com wrote:
> On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
>> Nevermind. for j in range(1,8) should be for j in range(8).
>
> I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero.
>
> I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`.  But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step.
>

"First instinct"?  "I expected"?  The Python docs might not be perfect, 
but they were certainly adequate enough to get me going 15 years ago, 
and since then they've improved.  So where is the problem, other than 
failure to RTFM?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list