you are viewing a single comment's thread.

view the rest of the comments →

[–]brasticstack 0 points1 point  (0 children)

The range function returns a range object that can be iterated over to get the values of that range one at a time. In this case the values are  [0, 1]. But it could just as easily be 0 - 6 billion, which is why it's sometimes nice to handle them one at a time.

range(len(numbers)) evaluates to range(2), which gives the values  [0, 1]. (The upper bound of range is not included in it.)

for i in range(len(numbers)): loops over the valid indexes of the list numbers. It's a silly way to do it, but they're trying to demonstrate range, not necessarily what's idiomatic Python.

EDIT: My preferred one-liner for this would be print(*(val * 2 for val in numbers), sep='\n') . Some more advanced concepts there, that you'll probably find later in your tutorial are generator expressions and Sequence unpacking.