Python Practice › String Programs › Program 61
Index of a character
Write a Python program to print the index of a character in a string.
Input
"Sqatools", "q"
Output
The index of q is 1
Approach
find()returns the first index (or -1).
Solution
text = "Sqatools"ch = "q"print(f"The index of {ch} is {text.find(ch)}")Output
The index of q is 1
Learn the concept
New to this topic? Read the lesson, then come back.