Can i iterate through a string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can i iterate through a string

for example for 'hello'. is it possible to iterate to print h \n e \n l \n l \n o \n

5th Feb 2017, 1:11 PM
harris
1 Answer
+ 6
Yes, string's an iterable: for char in string: print(char) That prints all the characters, each on separate line.
5th Feb 2017, 2:25 PM
DotJason