Python Practice › String Programs › Program 61

Index of a character

EasyString Programs · 61 of 106

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

Advertisement
Input
"Sqatools", "q"
Output
The index of q is 1

Approach

  1. find() returns the first index (or -1).

Solution

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

More string programs

← All 106 String Programs

Leave a Comment