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
- Take a string as input.
- Use for loop to iterate over each character of the string.
- Find the index of the character using Index().
- 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