Skip to content

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

  • by

Use the for-loop and enumerate function to print the index of the character in a string.

Python program to print the index of the character in a string Example

Simple example code.

str1 = "PYTHON"

for index, char in enumerate(str1):
    print(char, "position at", index)

Output:

Python program to print index of character in string

Do comment if you have any doubts and suggestions on this python index char topic

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading