---
title: The for Loop in Python
source: https://app.sythra.ai/learn/python/for-loop-python
topic: Python
updated: 2026-08-12
publisher: Sythra (https://app.sythra.ai)
---

# The for Loop in Python

A for loop in Python pulls values one at a time from a sequence — like range(), a string, or a list — and runs its body once per value, stopping automatically when the sequence is exhausted.

_Source: [https://app.sythra.ai/learn/python/for-loop-python](https://app.sythra.ai/learn/python/for-loop-python) — free to read on Sythra._

## Key points

- for i in range(1, 6) loops over 1, 2, 3, 4, 5 — it stops before the stop value, not at it
- for loops can iterate directly over strings, lists, and other sequences
- range(start, stop, step) lets you control where to begin, where to stop, and how much to jump each time
- A negative step lets range() count downward
- Use for when you know what you're iterating over; use while when you're waiting on a condition

[The while loop](/learn/python/while-loop-python) is great when you don't know in advance how many times you'll repeat — you just keep going until some condition changes. But very often, you already know exactly what you want to repeat over — like "every number from 1 to 10" or "every letter in this word." For that, Python gives you something more direct: the **for loop**.

```python
for i in range(1, 6):
    print(i)

# Output:
# 1
# 2
# 3
# 4
# 5
```

## What you will learn

- How a `for` loop pulls values one at a time from a sequence
- Why `range(1, 6)` stops before 6, not at 6
- Looping over strings and lists directly
- How to control start, stop, and step with `range()`
- When to reach for `for` instead of `while`

## Breaking down for i in range(1, 6):

- `range(1, 6)` — creates a sequence of numbers starting at 1, and stopping **before** 6. So you get 1, 2, 3, 4, 5 — five numbers, not six. This "stop before, not at" behavior catches almost every beginner at least once, so keep an eye on it.
- `for i in ...` — this means: one at a time, take each value out of that sequence, call it `i` for this trip through the loop, and run the body.
- The loop automatically runs once for every single item in the sequence, and then stops on its own — no `break`, no condition to write yourself, no risk of an infinite loop by accident.

## Looping over strings and lists

You can also loop over the actual characters in a piece of text:

```python
word = "cat"
for letter in word:
    print(letter)

# Output:
# c
# a
# t
```

Or loop over items inside a [list](/learn/python/lists-in-python):

```python
fruits = ["apple", "banana", "mango"]
for fruit in fruits:
    print(fruit)

# Output:
# apple
# banana
# mango
```

> **for vs. while — quick rule of thumb:** 

## range() with a start, stop, and step

`range()` actually accepts up to three numbers — a start, a stop, and a step:

```python
for i in range(0, 10, 2):
    print(i)

# Output:
# 0
# 2
# 4
# 6
# 8
```

The third number (`2` here) is the **step** — how much to jump by on each repeat. If you leave it out, Python assumes a step of 1, like in the very first example. You can even count backwards using a negative step:

```python
for i in range(5, 0, -1):
    print(i)

# Output:
# 5
# 4
# 3
# 2
# 1
```

This is actually a cleaner way to write the countdown function from the [while loop article](/learn/python/while-loop-python) — no manual decrement needed.

## Common mistakes

- Expecting `range(1, 6)` to include 6 — it stops **before** the stop value
- Reaching for `while` with a manual counter when a plain `for i in range(...)` would be shorter and safer
- Forgetting that a negative step is required to count downward with `range()`
- Trying to modify a list while looping over it directly with `for` — this can skip items unpredictably

> **Practice with Sythra:**  [Practice with AI tutor](https://app.sythra.ai/pricing)

## FAQ

### Why doesn't range(1, 6) include 6?

range() in Python always stops before its stop value, never at it. range(1, 6) produces 1, 2, 3, 4, 5 — five numbers. This half-open behavior is consistent across Python's slicing and indexing too.

### Can a for loop iterate over a string?

Yes. A string is a sequence of characters, so for letter in word: loops over each character one at a time, in order.

### What are the three arguments to range()?

range(start, stop, step): start is the first number (default 0), stop is where it stops before, and step is how much to increase by each time (default 1). A negative step counts downward.

### Should I use for or while in Python?

Use for when you already know what you're iterating over — a range of numbers, characters in a string, or items in a list. Use while when you're repeating until some condition changes, and you don't know the number of repeats in advance.

## Related

- [The while Loop in Python](https://app.sythra.ai/learn/python/while-loop-python) — Condition-based repetition — the loop for when you don't know the count in advance.
- [The do-while Equivalent in Python (and Nested Loops)](https://app.sythra.ai/learn/python/do-while-python) — Simulating run-at-least-once loops and nesting loops.
- [More Tools for Iteration in Python](https://app.sythra.ai/learn/python/iteration-tools-python) — continue, enumerate(), zip(), comprehensions, and generators.
- [Lists in Python](https://app.sythra.ai/learn/python/lists-in-python) — The sequence type you'll loop over most often.
- [Python course hub](https://app.sythra.ai/learn/python) — All free Python explainers and the path into Agentic practice.

---

Written by Sythra — Learn machine learning by building. Practice this topic with Sythra's AI tutor: https://app.sythra.ai/pricing
