Python Program to Find Position of Characters in String Using Index: In this program, we have to find the position of characters in the string by using an index. So after reading the question, a simple argument arises for me: we iterate through the string and check each character against the required one. As soon as the character is matched throughout the string, we will print its index.
Also read:- Python program to Swap Two Values
Python Program to Find the position of a character in a given string Source Code
s = input("Enter the string:- ") k = input("Enter the character to find:- ") for i in range(len(s)): if(s[i] == k): print(i)
Enter the string:- Iconic Python Enter the character to find:- o 2 11
Also read:- Python Program to Find the Square Root