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
Correct: stop is not included.
- ✗
It returns a list of numbers with a default step of 0
Why it's wrong here
Default step is 1, step of 0 raises ValueError.
- ✗
It can only be used with integers
Why it's wrong here
True but does not describe behavior; range also works with float? No, only integers.
- ✗
It generates a list of numbers from start to stop inclusive
Why it's wrong here
Range is exclusive of the stop value.
Go deeper
Related to this question
About these practice questions
One of 498 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.