Python – Loop Lists

1. What Does β€œLoop Lists” Mean?

Looping a list means going through each item one by one.

In simple words:
πŸ‘‰ Python looks at every item in the list and does something with it.

2. Loop Through List Using for

The easiest and most common way is using a for loop.

Example

fruits = ["apple", "banana", "orange"]

for fruit in fruits:
print(fruit)

Output:

apple
banana
orange

3. Loop Through List Using Index

You can loop using index numbers.

Example

colors = ["red", "blue", "green"]

for i in range(len(colors)):
print(colors[i])

4. Loop Using while

You can also use a while loop.

Example

numbers = [10, 20, 30]
i = 0

while i < len(numbers):
print(numbers[i])
i += 1

5. Loop and Do Calculation

Example

nums = [1, 2, 3, 4]
total = 0

for n in nums:
total += n

print("Sum:", total)

6. Loop with Condition

Example

numbers = [5, 10, 15, 20]

for n in numbers:
if n > 10:
print(n)

7. Loop and Change List Items

Example

nums = [1, 2, 3]

for i in range(len(nums)):
nums[i] = nums[i] * 2

print(nums)

8. Loop Using List Comprehension (Simple Intro)

A short way to loop and create a new list.

Example

numbers = [1, 2, 3]
new_numbers = [n * 2 for n in numbers]

print(new_numbers)

9. Common Beginner Mistakes

❌ Forgetting Indentation

for x in fruits:
print(x)

βœ” Correct:

for x in fruits:
print(x)

❌ Changing List Directly While Looping

for n in nums:
nums.remove(n)

βœ” Better:

for n in nums[:]:
nums.remove(n)

10. Simple Practice Examples

Example 1: Print All Names

names = ["Amit", "Ravi", "Sita"]

for name in names:
print(name)

Example 2: Count Items

items = ["pen", "book", "eraser"]
count = 0

for item in items:
count += 1

print(count)

Example 3: Print Even Numbers

nums = [1, 2, 3, 4, 5, 6]

for n in nums:
if n % 2 == 0:
print(n)

11. Summary (Loop Lists)

βœ” Loop means repeating
βœ” for loop is easiest
βœ” Can use index or value
βœ” Loops work with conditions
βœ” Very useful for real programs

πŸ“˜ Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • List Comprehension (easy)

  • Sort Lists

  • Copy Lists

  • Join Lists

  • List Exercises

Just tell me 😊

You may also like...