OneBite.Dev - Coding blog in a bite size

loop through each character in a string in python

Code snippet on how to loop through each character in a string in python

for char in a_string:
  print(char)

This code will loop through each character in a string, one character at a time. It starts by declaring a variable called char at the start of the loop. Then, it takes each character from the string one by one, and stores it in the char variable. Finally, it prints the stored character to the console. By doing this over and over again until it has gone through every character, it will loop through each character in the string.

python