ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
print(sum(range(1, 10, 2)), list(range(5))[-1:-4:-1])
  1. A. 25 [4, 3, 2]
  2. B. 20 [4, 3, 2]
  3. C. 25 [4, 3, 2, 1]
  4. D. 25 [3, 2, 1]

Correct answer: A. 25 [4, 3, 2]

range(1, 10, 2) is 1, 3, 5, 7, 9, which sums to 25. The slice [-1:-4:-1] starts at the last element (4) and steps back, stopping before index -4 (which is 1): [4, 3, 2].

More Python Programming questions

Exams that ask this topic