So far in this course, you’ve seen how to avoid writing C-style loops in Python. But what if you need to write a C-style loop, and it needs to be in Python?
If you take a closer look at the range()
built-in, you’ll see that you can call it with multiple parameters: start
, stop
, and step
. So you can use range()
in a way that closely maps to a C-style loop.
nelsonblue24 on June 29, 2020
Where you say “n is the right-hand side value in that range or it’s the number of elements that you’re iterating over”, I suggest dropping the last part: “or it’s the number of elements that you’re iterating over.” That part conflicts with what you say later: “if you want to iterate over every tenth element, you would just use a step size of ten and then, instead of iterating over each element individually, you would jump ahead ten elements at a time.” I believe dropping the part I suggest dropping would reduce the chances of confusing students.