Lists & Tuples · Question 19 · Hard

Two slices with negative values are taken from a list. What does this print?

a = [10, 20, 30, 40, 50]
print(a[-3:-1], a[::-2])
  1. [30, 40] [50, 30, 10]
  2. [30, 40, 50] [50, 30, 10]
  3. [30, 40] [40, 20]
  4. [20, 30] [50, 30, 10]
Answer and explanation

Answer: A. [30, 40] [50, 30, 10]

Explanation: a[-3:-1] starts at the third element from the end (30) and stops before the last one, giving [30, 40]. a[::-2] starts from the last element and takes every second item going left: 50, 30, 10.

Previous: Student records are sorted by marks in descending order using a key. In what… · Next: Tuples of different lengths are compared. What does this print?

Practise lists & tuples

Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.

More lists & tuples questions

More python practice

Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators

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