Python Practice › String Programs › Program 99

Index of each character

EasyString Programs · 99 of 106

Write a Python program to print the index of each character in a string.

Advertisement
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

  1. enumerate() gives index and character.

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs