🎓 EASYTUTORGUIDE · Complete Python Course

Very beginner → professional Python · 60 chapters · 900 topics

EasyTutorGuide

Chapter 12: Loops

Complete Python lesson for very beginners. Technical words are explained in simple language, and every outline topic includes a practical example, expected output, steps, and practice.

Python CourseVery Beginner Friendly15 TopicsExamples + Output20 Q&A
Chapter 12 · 15 topics
100%

Chapter Overview

This Python tutorial chapter covers Loops through 15 connected topics. Work through the examples in order, check the expected output, and complete the practice after each topic.

  • 12.1 Iteration
  • 12.2 while Loops
  • 12.3 for Loops
  • 12.4 range()
  • 12.5 Loop Variables
  • Plus 10 additional Python topics in this chapter.

12.1 Iteration

Iteration is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Iteration (a Python idea used while learning loops).

Python / Practical Example

for color in ["red", "blue"]:
    print(color)

Expected Output

red
blue

Step-by-Step Explanation

  1. The list is iterable.
  2. for assigns each item to color in turn.
  3. The indented body runs once per item.
Practice: Re-type the example for “Iteration”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.2 while Loops

while Loops is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: while Loops (a Python idea used while learning loops).

Python / Practical Example

count = 1
while count <= 3:
    print(count)
    count += 1

Expected Output

1
2
3

Step-by-Step Explanation

  1. Initialize a loop variable.
  2. Repeat while the condition is true.
  3. Update the variable so the loop can finish.
Practice: Re-type the example for “while Loops”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.3 for Loops

for Loops is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: for Loops (a Python idea used while learning loops).

Python / Practical Example

for color in ["red", "blue"]:
    print(color)

Expected Output

red
blue

Step-by-Step Explanation

  1. The list is iterable.
  2. for assigns each item to color in turn.
  3. The indented body runs once per item.
Practice: Re-type the example for “for Loops”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.4 range()

range() is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: range() (a Python idea used while learning loops).

Python / Practical Example

for n in range(1, 4):
    print(n)

Expected Output

1
2
3

Step-by-Step Explanation

  1. range(1, 4) produces 1, 2, 3.
  2. The stop value is excluded.
  3. for visits each generated integer.
Practice: Re-type the example for “range()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.5 Loop Variables

Loop Variables is part of Loops. In simple language, it means a name that refers to a value.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Loop Variables (a name that refers to a value).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Loop Variables”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.6 Nested Loops

Nested Loops is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Nested Loops (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Nested Loops”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.7 break

break is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: break (a Python idea used while learning loops).

Python / Practical Example

for n in range(5):
    if n == 2:
        break
    print(n)

Expected Output

0
1

Step-by-Step Explanation

  1. Loop through numbers.
  2. break exits the nearest loop immediately.
  3. Values after the break point are not printed.
Practice: Re-type the example for “break”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.8 continue

continue is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: continue (a Python idea used while learning loops).

Python / Practical Example

for n in range(4):
    if n == 2:
        continue
    print(n)

Expected Output

0
1
3

Step-by-Step Explanation

  1. continue skips the rest of the current iteration.
  2. The loop itself continues.
  3. Only 2 is skipped.
Practice: Re-type the example for “continue”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.9 pass

pass is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: pass (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “pass”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.10 Loop else

Loop else is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Loop else (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Loop else”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.11 Infinite Loops

Infinite Loops is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Infinite Loops (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Infinite Loops”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.12 Iterating Strings

Iterating Strings is part of Loops. In simple language, it means text stored as characters.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Iterating Strings (text stored as characters).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Iterating Strings”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.13 Iterating Collections

Iterating Collections is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Iterating Collections (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Iterating Collections”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.14 Common Loop Patterns

Common Loop Patterns is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Common Loop Patterns (a Python idea used while learning loops).

Python / Practical Example

import re
text = "Order 123"
match = re.search(r"\d+", text)
print(match.group() if match else "none")

Expected Output

123

Step-by-Step Explanation

  1. Import re.
  2. The raw-string pattern \d+ means one or more digits.
  3. search() finds the first matching region.
Practice: Re-type the example for “Common Loop Patterns”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

12.15 Loop Projects

Loop Projects is part of Loops. In simple language, it means a Python idea used while learning loops.

It is one building block of loops and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Loop Projects (a Python idea used while learning loops).

Python / Practical Example

for n in range(3):
    print(n)

Expected Output

0
1
2

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Loop Projects”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

Common Beginner Mistakes

  • Copying code without predicting what each line does.
  • Ignoring the first useful error message or traceback location.
  • Mixing tabs/spaces or changing indentation accidentally.
  • Using data of the wrong type for an operation.
  • Trying to learn many advanced variations before mastering one small working example.

Chapter Practice

  1. Choose three topics from this chapter and re-type their examples without copying and pasting.
  2. For each example, change one input and predict the output first.
  3. Explain five technical terms from this chapter in your own beginner-friendly words.
  4. Create one small program that combines at least two chapter topics.
  5. Keep notes about errors you made and what fixed them.

Mini Project / Challenge

Create a small Python exercise that combines at least three ideas from Loops. Start with a tiny working version, test it, then improve it one step at a time.

  1. Choose three topics from this chapter.
  2. Write or adapt a small Python example using those topics.
  3. Predict the output before running the code.
  4. Test at least one different input.
  5. Write two sentences explaining what the program does and what you learned.

20 Questions & Answers

1. What is the main goal of Chapter 12?

The goal is to understand loops through small explanations, examples, and practice.

2. Should I memorize every command or method?

No. Understand the pattern, practice the common form, and learn how to read documentation when you need exact details.

3. Why are the examples small?

Small examples isolate one idea at a time, which makes errors easier to understand and fix.

4. What should I do when an example gives an error?

Read the last part of the traceback, check spelling and indentation, confirm the required package or file exists, and compare the input types with what the operation expects.

5. Why should I predict output before running code?

Prediction forces you to reason about the program instead of only copying it.

6. What should I remember about Iteration?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

7. What should I remember about while Loops?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

8. What should I remember about for Loops?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

9. What should I remember about range()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

10. What should I remember about Loop Variables?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

11. What should I remember about Nested Loops?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

12. What should I remember about break?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

13. What should I remember about continue?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

14. What should I remember about pass?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

15. What should I remember about Loop else?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

16. What should I remember about Infinite Loops?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

17. What should I remember about Iterating Strings?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

18. What should I remember about Iterating Collections?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

19. What should I remember about Common Loop Patterns?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

20. What should I remember about Loop Projects?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.