Repeat Any List, String, or Range with Python For Loops
Learn how to use Python for loops to repeat actions over lists, strings, and ranges — without copying the same line of code five times.
By the end of this video you will be able to loop over a mission checklist, spell out a mission code character by character, and run a countdown from any number — all in just two lines.
⏱ Chapters:
0:00 Intro — Arohas Code Lab
0:03 Five Print Statements — and Why That Number Will Keep Growing
0:12 How a For Loop Visits Every Item — The Core Mechanism
0:21 Looping Over the Mission Checklist — Lists in Action
0:31 Strings and Ranges — Two More Sequences Python Can Loop Over
0:42 The range() Surprise — Off-by-One Errors in Mission Numbering
0:53 For Loop Mental Model — and Your Planet Challenge
---
Challenge Solution
*Task:* Given `planets = ['Mercury', 'Venus', 'Earth']`, print each planet with its 1-based position number.
*Expected output:*
```
1. Mercury
2. Venus
3. Earth
```
*Solution:*
```python
planets = ['Mercury', 'Venus', 'Earth']
for i in range(len(planets)):
print(f'{i + 1}. {planets[i]}')
```
*How it works:*
`range(len(planets))` produces 0, 1, 2 — one index per planet.
`i + 1` shifts each index to human-readable 1-based numbering.
`planets[i]` looks up the planet at that position.
*Alternative using `enumerate`* (bonus — not covered in the video):
```python
for i, planet in enumerate(planets, start=1):
print(f'{i}. {planet}')
```
`enumerate(planets, start=1)` pairs each planet with a counter starting at 1, skipping the `i + 1` adjustment entirely.
---
#Python #ForLoops #PythonBeginner #LearnPython #CodingForBeginners #PythonTutorial #ArohasCodeLab
En esta página del sitio puede ver el video en línea Python For Loops - Repeat Code Like a Pro de Duración hora minuto segunda en buena calidad , que subió el usuario Arohas Code Lab 05 junio 2026, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto veces y le gustó 0 a los espectadores. Disfruta viendo!