Print the index of each character in a string.

In this program, we will take a string as input and print the index of each character in a string.

Steps to solve the program
  1. Take a string as input.
  2. Use for loop to iterate over each character of the string.
  3. Find the index of the character using Index().
  4. Print the output.
				
					#Input string
str1 = "python"

for char in str1:
    print(f"Index of {char} is {str1.index(char)}")
				
			

Output :

				
					Index of p is 0
Index of y is 1
Index of t is 2
Index of h is 3
Index of o is 4
Index of n is 5
				
			

reverse words in a string using python.

find the first repeated character in a string and its index.

Leave a Comment