Programming · Flashcard

What does list(range(1, 10, 3)) return?

  • A[1, 4, 7] — the step advances by 3 and stops before 10
  • B[1, 4, 7, 10] — the stop value ends the sequence inclusively
  • C[1, 2, 3] — the third argument sets how many items to produce
  • D[3, 6, 9] — the step also decides where the sequence begins

Why this is the answer

range(start, stop, step) counts from start in increments of step and stops before reaching stop, giving 1, 4 and 7 — the next value, 10, is excluded. The stop is never included, the third argument is a step rather than a count of items, and the sequence begins at the start argument, not at the step.

Official docs
Study in Gnoseed →