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
Nesta página do site você pode assistir ao vídeo on-line Python For Loops - Repeat Code Like a Pro duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Arohas Code Lab 05 Junho 2026, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto vezes e gostou 0 espectadores. Boa visualização!