Python Learning Series · @onlysamarrr · Day 10 / 30
Day 10 teaches the for loop and range(). range(5) gives 0, 1, 2, 3, 4: the end value is never included.
Phase: Beginner · Reels: 46/450 – 50/450
Day 10 teaches the for loop and range(). range(5) gives 0, 1, 2, 3, 4: the end value is never included.
for i in range(5):
print(i, end=" ")
print()
print(list(range(2, 11, 2)))
print(sum(range(1, 11)))
for i, f in enumerate(["mango", "banana"], start=1):
print(i, f)
for i in range(1, 4):
print(f"5 x {i} = {5 * i}")
0 1 2 3 4 [2, 4, 6, 8, 10] 55 1 mango 2 banana 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15
Tables, lists of items and repeated calculations in apps are all for loops.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. What numbers does range(5) give?
Q2. What is sum(range(1, 11))?
Q3. What is the last value of range(2, 11, 2)?
| 46/450 | Concept | for loop basics |
| 47/450 | Live demo | range(start, stop, step) |
| 48/450 | Common mistake | range(5) mein 5 nahi aata |
| 49/450 | Quiz | Quiz: 1 se 10 tak sum |
| 50/450 | Interview / real life | Real life: table generator |