Python For Loops - Repeat Code Like a Pro

Veröffentlicht am: 05 Juni 2026
auf dem Kanal: Arohas Code Lab
0

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


Auf dieser Seite können Sie das Online-Video Python For Loops - Repeat Code Like a Pro mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Arohas Code Lab 05 Juni 2026 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!