Question 1: Slicing and List Extraction

This is a simple question on list slicing and list extraction.

What will be the output of the following code:

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

Select an option:🤔🧐















B: is the correct answer.

The code my_list[2:4] selects elements starting from index 2 (inclusive) up to, but not including, index 4. Therefore, it selects the elements at indices 2 and 3, which are 3 and 4 respectively. The resulting list is [3, 4].

Leave a Reply