Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

When using the `range()` function in a Python `for` loop, what are the default `start` value and `step` (increment) value if only a single `stop` argument is provided (e.g., `range(5)`)?
Options
A Starts at 1, increments by 1.
B Starts at 0, increments by 1.
Correct Answer
C Starts at 0, increments by 0 (no increment).
D Starts at 1, increments by 0 (no increment).
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 78 of the document clarifies: "The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number."

Hint

Consider how array indices or sequences often begin in computer programming, and the most common increment needed for counting.

Question Info