Python For Loops - Repeat Code Like a Pro

Published: 05 June 2026
on channel: 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


On this page of the site you can watch the video online Python For Loops - Repeat Code Like a Pro with a duration of hours minute second in good quality, which was uploaded by the user Arohas Code Lab 05 June 2026, share the link with friends and acquaintances, this video has already been watched times on youtube and it was liked by 0 viewers. Enjoy your viewing!