Conditions & Loops · Question 6 · Easy

range() is given a negative step. What list does this print?

print(list(range(5, 0, -2)))
  1. [5, 3, 1, 0]
  2. [5, 3]
  3. [5, 3, 1]
  4. [4, 2, 0]
Answer and explanation

Answer: C. [5, 3, 1]

Explanation: The range starts at 5 and moves down by 2 while the value is still greater than the stop value 0. That gives 5, 3 and 1; the next value, -1, is past the stop.

Previous: A while loop keeps subtracting 2 from n. What is n when the loop ends? · Next: A loop over the letters of a word stops at the letter p. What is printed?

Practise conditions & loops

Try a fresh set of conditions & loops questions with an explanation after every answer, free and without signing up: Conditions & Loops practice. Or sit a full placement mock test.

More conditions & loops questions

More python practice

Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge