Python Basics — Day 6 Loops (for / range)
Aspiring Full-Stack Developer | Python · Django · React · SQL | documenting my learning journey
Building skills in Python and full-stack development, with a focus on web apps and system design
Junior developer in training — Python, Django, React — preparing for a career in full-stack engineering
From Python basics to full-stack projects, sharing my progress as I grow into a developer
Future full-stack engineer | Learning in public: Python, APIs, Databases, and Web Development
Day 6 – Loops (for / range)
01. What is a Loop?
Loops are used when you want to repeat the same action multiple times.
In Python, the two main types of loops are for and while.
(Today we focus on for loops.)
02. Basic for Loop
A for loop iterates over iterable objects like lists, strings, or ranges.
fruits = ["Apple", "Banana", "Grape"]
for f in fruits:
print(f)
👉 Output:
Apple
Banana
Grape
03. The range() Function
A built-in function commonly used for number sequences.
range(end) # 0 to end-1
range(start, end) # start to end-1
range(start, end, step) # start to end-1 with step
Examples:
for i in range(5):
print(i) # 0,1,2,3,4
for i in range(1, 6):
print(i) # 1,2,3,4,5
for i in range(2, 11, 2):
print(i) # 2,4,6,8,10
04. Nested Loops
A for loop can be placed inside another for loop.
for i in range(2, 4): # 2, 3
for j in range(1, 4): # 1, 2, 3
print(i, "*", j, "=", i * j)
05. Looping Through Strings
Strings are iterable, so you can loop through each character.
for ch in "Python":
print(ch)
06. Practice Examples
Example 1: Sum of Numbers from 1 to 10
total = 0
for i in range(1, 11):
total += i
print("Sum:", total)
Example 2: Multiplication Table (2 times table)
for i in range(1, 10):
print(f"2 x {i} = {2*i}")
Example 3: Iterating Over a List
names = ["Tom", "Anna", "Sabin"]
for n in names:
print(f"Hello, {n}!")