+ 1
A for loop iterates through any iterable object one item at a time until all iterable elements have been explored. As a list has an index it can be called directly in a for a loop. You also could iterate over the list using the range of the length of the list range(len(list)) which would mimic the default beviour of just iterating through the list. Option 1: list = [1, 2, 3, 4] for num in list: print(num) Option 2: list = [1, 2, 3, 4] for i in range(len(list)): print(list[i])
18th Jul 2022, 11:21 AM
jht
jht - avatar