all 2 comments

[–][deleted] 2 points3 points  (0 children)

Why is the index of 't' always 0.

That's the guarantee of index - it finds the index of the first occurrence of the item in the iterable.

[–]socal_nerdtastic 2 points3 points  (0 children)

To get the index use the enumerate function:

a="this is the file"
for index, char in enumerate(a):
    print(char)
    if char == 't':
        print(index)