Last Updated : 11 Jul, 2025
In this article, we will learn how to iterate over the characters of a string in Python. There are several methods to do this, but we will focus on the most efficient one. The simplest way is to use a loop. Let’s explore this approach.
Using for loopThe simplest way to iterate over the characters in a string is by using a for loop. This method is efficient and easy to understand.
Python
s = "hello"
for char in s:
print(char)
Explanation: for char in s: This line loops through the string s, with char representing each character in s one by one.
Using enumerate for Index AccessIf we need both the character and its index then enumerate() is a great choice. It returns both values in each iteration.
Python
s = "hello"
for i, char in enumerate(s):
print(f"Index {i}: {char}")
Index 0: h Index 1: e Index 2: l Index 3: l Index 4: o
Explanation:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4