PCEP Control Flow, Loops, Lists and Logic Practice Question
Which of the following best describes the behavior of the 'range' function in a for loop?
⚠ Common exam trap
Python Institute often tests the misconception that `range()` returns a list or that the stop value is inclusive, leading candidates to pick option D, but in Python, `range()` returns a lazy sequence and the stop value is always exclusive.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
It generates a sequence of numbers from start to stop exclusive
The built-in `range()` function in Python generates an immutable sequence of numbers from the start value (default 0) up to, but not including, the stop value. When used in a `for` loop, it yields each number in the sequence one at a time, making it ideal for iterating a fixed number of times. The stop value is exclusive, meaning the loop body does not execute for the stop value itself.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
It generates a sequence of numbers from start to stop exclusive
Why this is correct
range(start, stop) produces integers beginning at start and stopping before stop, so the stop value is excluded from the sequence. The step argument defaults to one. This exclusive upper bound is the defining behaviour tested, distinguishing it from inclusive iteration constructs.
- ✗
It returns a list of numbers with a default step of 0
Why it's wrong here
A step of zero raises ValueError because the sequence can never advance, so no numbers are produced at all. It is tempting because zero suggests no increment or a default, and a step of one would be correct as the actual default increment when the third argument is omitted.
- ✗
It can only be used with integers
Why it's wrong here
The range function accepts any integer arguments, but its real constraint is that arguments must be integers, not that it works only with them; floats raise TypeError. It is tempting because range is commonly paired with integer counters, yet it also generates sequences for indexing, slicing and iteration counts, so the claim misstates its actual limitation.
- ✗
It generates a list of numbers from start to stop inclusive
Why it's wrong here
The stop value is exclusive, so range(1, 5) yields 1, 2, 3, 4 and never reaches 5, contradicting the stated inclusive behaviour. It is tempting because everyday counting often includes the endpoint, and inclusive bounds would be correct for slicing syntax such as list[1:5].
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.