ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
x = [10, 20, 30, 40, 50]
print(x[-1], x[len(x) // 2], x[-2:])
  1. A. 50 30 [40, 50]
  2. B. 50 20 [40, 50]
  3. C. 10 30 [40]
  4. D. 50 30 [50, 40]

Correct answer: A. 50 30 [40, 50]

x[-1] is the last element, 50. len(x) // 2 = 5 // 2 = 2, and x[2] is 30. x[-2:] starts two from the end and runs to the end in the original order: [40, 50].

More Python Programming questions

Exams that ask this topic