Like the articles? Buy the book! Dead Simple Python by Jason C. McDonald is available from No Starch Press.
The previous section more or less e...
For further actions, you may consider blocking this person and/or reporting abuse
I find it fairly easy to intuit how range works, because mostly I've used it for
range(len(something))
(alternativelyrange(1,len(something))
) in which case it grabs every index ofsomething
. Like, iflen(something) == 10
, then the last item insomething
has an index of 9, so it makes sense that range wouldn't want to try to grab an index 10.Sometimes this throws me off trying to use actual numbers in
range()
, though XDFor some reason I often have trouble confusing the syntax of slices and ranges, though. Less as I practice more, but it's not uncommon for my first entry of a statement to have
:
where it should have,
, or vice versa. Oops.(Also, stepping by -1 is fun ;) )
Such a great series, just what I need to get started with Python again! I am slightly confused around the enumeration examples though, the first snippet and second snippet read the same other than the output text, should the first snippet read as below with a 0 rather than a 1 on the enumeration?
Cheers
Marc
You could do that. I deliberate used a
1
because I wanted to use 1-based indexing in my output, instead of 0-based. I personally liked it better, that's all.If you want to start from
0
, as in your code, you can actually omit the second argument altogether, and just useenumerate(range(10,101,10))
.That makes sense, however in order to get the result provided in the post for your first snippet, you would have needed to have put a 0 or omitted the second argument, which is what I found confusing as the second snippet then shows the correct results for using a 1.
Cheers
Marc
Oh! Derp, I see it now. Sorry, typo! Fixed.
No worries! Just glad it wasn’t me not getting it.
Keep up the good work, this is a great series!
Cheers
Marc
Great article! Just a heads up, I found a typo when you were talking about reversed()
Awesome! What was the typo? Do you remember?
He may be referring to the end of the first paragraph in the section on
reversed()
: you wrote "reserved" instead. I was going to point out the same thing.Good catch! Thanks.
There are typos in some
print
's — you forgot to close)
brackets.Thanks for your huge work, it helps me a lot!
Oh, thanks for catching that!