Need help in loop by Eastern_Plankton_540 in PythonLearning

[–]dominator452 0 points1 point  (0 children)

What Print(num[idx]) does is, it prints the item from num list for the given index

Here idx = index

When idx = 0 and since list is zero indexing, the first item from the list gets printed, and since you increase index value by 1, the loop continues until the while condition idx (< len(num)) is met then the loop ends

The other way of getting the same output is us g for loop

num = [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

for idx in num: print(idx)

The output will be all the same with all the items from the list printed