Python Program to Print Characters in a String

Write a Python program to Print Characters in a String with a practical example.

Python program to Print Characters in a String Example 1

This python program allows the user to enter a string. Next, it prints the characters inside this string using For Loop. Here, we used For Loop to iterate every character in a String. Inside the Python For Loop, we used the print statement to print characters inside this string.

TIP: Please refer String article to understand everything about Strings in Python.

# Python program to Print Characters in a String
 
str1 = input("Please Enter your Own String : ")
 
for i in range(len(str1)):
    print("The Character at %d Index Position = %c" %(i, str1[i]))
Python program to Print Characters in a String 1

Python program to return Characters in a String Example 2

This python program to display characters in a string is the same as the above. However, we just replaced the For Loop with While Loop.

# Python program to Print Characters in a String
 
str1 = input("Please Enter your Own String : ")
i = 0

while(i < len(str1)):
    print("The Character at %d Index Position = %c" %(i, str1[i]))
    i = i + 1

Python print string characters output

Please Enter your Own String : Tutorial Gateway
The Character at 0 Index Position = T
The Character at 1 Index Position = u
The Character at 2 Index Position = t
The Character at 3 Index Position = o
The Character at 4 Index Position = r
The Character at 5 Index Position = i
The Character at 6 Index Position = a
The Character at 7 Index Position = l
The Character at 8 Index Position =  
The Character at 9 Index Position = G
The Character at 10 Index Position = a
The Character at 11 Index Position = t
The Character at 12 Index Position = e
The Character at 13 Index Position = w
The Character at 14 Index Position = a
The Character at 15 Index Position = y