This works well if you only need to read the elements of the list. But if you want to write or update the elements, you need the indices. A common way to do that is to combine the functions range and len:
p = [3, 4, "Me", 3, [], "Why", 0, "Tell", 9.3]
for ch in p:
print(ch)
8
Iteration by item will process once for each item in the sequence, even the empty list.
9
Yes, there are nine elements in the list so the for loop will iterate nine times.
15
Iteration by item will process once for each item in the sequence. Each string is viewed as a single item, even if you are able to iterate over a string itself.
Error, the for statement needs to use the range function.
The for statement can iterate over a sequence item by item.
This loop traverses the list and updates each element. len returns the number of elements in the list. range returns a list of indices from 0 to n-1, where n is the length of the list. Each time through the loop, i gets the index of the next element. The assignment statement in the body uses i to read the old value of the element and to assign the new value.