What will be the output of the following Python program?

a = [1, 2, 3, 4, 5]
print(a[1:4])
                        

Options

  • A. [1, 2, 3]
  • B. [2, 3, 4]
  • C. [2, 3, 4, 5]
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. [2, 3, 4]

Detailed Explanation

In Python slicing, the starting index is included but the ending index is excluded.