Python Practice › String Programs › Program 99
Index of each character
Write a Python program to print the index of each character in a string.
Input
"sqatools"
Output
Index of s is 0 Index of q is 1 Index of a is 2 Index of t is 3 Index of o is 4 Index of o is 5 Index of l is 6 Index of s is 7
Approach
enumerate()gives index and character.
Solution
for i, ch in enumerate("sqatools"): print(f"Index of {ch} is {i}")Output
Index of s is 0 Index of q is 1 Index of a is 2 Index of t is 3 Index of o is 4 Index of o is 5 Index of l is 6 Index of s is 7
Learn the concept
New to this topic? Read the lesson, then come back.