Hi there, welcome to the forums.
There is some expectation on you as the learner to experiment with the knowledge imparted during the lesson on your own time. One should not necessarily expect to simply complete the lesson and arrive at a point of complete and thorough understanding.
If you are struggling to understand loops, the fix for this is to write some code using them and observe how they work. Can you write a functional loop? Can you break that code and understand why it no longer works? Can you take a broken piece of code using a loop, find and understand the flaw, and fix it? These are skills you will need to work on, as with any learning experience, in your own time beyond the “classroom” of the learning environment.
It should not be completely new at all, if you have completed the material on loops.
The loop itself is not particularly complex:
for index in range(1, len(lst), 2):
for loops work by defining an iterator to loop over, and stepping through it.
The iterator in this case is
range(1, len(lst), 2). The documentation for
range() is available here.
range(1, len(lst), 2) is creating an iterable which starts at
1, ends at
len(lst) and increments by
2 each time. For the example list given,
[4, 3, 7, 10, 11, -2],
6, so our iterable looks like:
[1, 3, 5] *
for loop then takes each of these values in turn, and plugs them into the code inside the loop.
# iterable is [1, 3, 5]
# 1st iteration, index = 1
# 2nd iteration, index = 3
# 3rd and final iteration, index = 5
Hope that helps, but in any case if you’re struggling I would again recommend that you experiment with loops on your own.
* The iterable is not a list, but an instance of the
range type. For simplicity, however, I have expressed it here as a list.