Google News
logo
Python Program to Return an iterator from a string
In the following example of Python program To return an iterator from a string, we can simply use the `iter()` built-in function :
Program :
my_string = "Hello, world!"
my_iterator = iter(my_string)

# Iterate through the iterator and print each character
for char in my_iterator:
    print(char)
Output :
H
e
l
l
o
,
 
w
o
r
l
d
!