Iterate over Characters of a String
To iterate over the characters of a string in Python, we can use use for loop statement.
The following code snippet shows how to iterate over the characters of a string
myString using for loop.
for ch in myString: //code
In the following program, we take a string in
name variable, and iterate over the characters of the string using for loop.
myString = 'apple' for ch in myString: print(ch)Try Online
a p p l e
In the above program(s), we have used the following Python concepts. The links have been provided for reference.
- Initialize string using single quotes
- For Loop
- Python print() builtin function
In this Python Tutorial, we learned how to iterate over the characters of a string in Python using for loop statement.