Thursday 23 September 2021

Python: Print character one at a time in string

Using ‘for’ loop, you can print the characters one at a time.

 

print_char_by_char.py 

def print_chars(str):
    for ch in str:
        print(ch)

print_chars('Hello World')

 

Output

H
e
l
l
o
 
W
o
r
l
d

 

 


Previous                                                    Next                                                    Home

No comments:

Post a Comment