Skip to content
dreamcode
dreamcode
Map
Collection loops
Lesson 15 of 77
+15 XP on finish
PYTHON BASICSChapter 3 · Loops and iteration

Climbing collections

You can loop over lists, but did you know you can also loop over strings? A loop over a string goes character by character, processing one letter at a time.

Worked example

How it reads

  • for char in word: assigns each letter of "neon" to char in sequence
  • char.upper() converts the current letter to uppercase
Cloud tip: Looping through characters or items is called iteration. It is one of the most common tasks in programming.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Loop over the letters of "moonlight" and count the vowels (a, e, i, o, u). Print the count: 3.

Press Run to check your work.