Iterate over Characters of a String
To iterate over the characters of a string in Python, use For loop statement. During each iteration of the for loop, we get to access each character of the string.
The syntax to access each character ch of the string s is
for ch in s: print(ch)
In this example, we will read a string into variable s, and iterate over the characters using for-in loop.
x = input('enter a string: ') for ch in x: print(ch)
enter a string: hello h e l l o
In this tutorial of Python Examples, we learned how to iterate over the characters of a given string using For Loop, with the help of well detailed examples.