KnowledgeBoat Logo
|

Informatics Practices

Find the output of the following code:

number = [1, 5, 7, 0, 4]
print(number[2:3])
  1. [5]
  2. [7]
  3. [7,0]
  4. None of these

Python List Manipulation

1 Like

Answer

[7]

Reason — The slice number[2:3] extracts a subset of the list starting from index 2 (inclusive) up to, but not including, index 3. In this case, index 2 corresponds to the element 7 in the list number. Therefore, number[2:3] results in [7].

Answered By

2 Likes


Related Questions