Python Program to find position of characters in a string using index

Python Program to find Position of Characters in a String using Index

In this article, we will be solving question based on strings in Python. According to the question we have to find position of characters in a string using index.

If you like the article content, then share it in your coding groups so that more people can take advantage of the content. So, without wasting any time let's solve this question.

Question - Write a Python Program to find position of characters in a string using index

Python Program to find position of characters in a string using index



Question -
 
Write a Python Program to find position of characters in a string using index

Python Program to find position of characters in a string using index - In this program we have to find position of characters in a string using index. So after reading the question, a simple logic comes to mind that we will iterate through the string and will the check each character with the required one. As the character matches throughout the string we will print it's index.

Here's the code for the same.

s = input("Enter the string:- ")
k = input("Enter the character to find:- ")

for i in range(len(s)):
    if(s[i] == k):
        print(i)


Output

Enter the string:- Iconic Python
Enter the character to find:- o
2
11


So, I hope you liked the article and you would have found the content of the article useful and helpful for you. Share this article in your coding communities so that more people can take advantage of the content. Also, In case of any doubt feel free to ask in the comments below.

For More Such Python Programs - Click Here

Enjoy Coding!!!


Also Read :-

Extract Phone Number Details Using Python





For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment (0)

Previous Post Next Post