For Loop with Strings
1 min read ·
A string in Python is a sequence of characters.
A
for loop can iterate over a string character by character.Basic Syntax
chstores one character at a time- Loop runs until the string ends
Simple Example
Loop Through String Using Variable
String with Spaces
- Space is also treated as a character
Using range() with String Index
Conditional Logic with String Loop
Counting Characters
Common Mistake
Caution
for loop works with iterable objects like strings, not numbers.