KnowledgeBoat Logo

Computer Science

Observe the given code and select the appropriate output.

Tuple given: tup1 = (10, 20, 30, 40, 50, 60, 70, 80, 90)

What will be the output of: print(tup1[3:7:2])

  1. (40, 50, 60, 70, 80)
  2. (40, 50, 60, 70)
  3. (40, 60)
  4. Error

Python Tuples

3 Likes

Answer

(40, 60)

Reason — The slice tup1[3:7:2] extracts elements starting from index 3 up to index 6, with a step of 2. This means it selects elements at indices 3, 5, resulting in the tuple (40, 60). The print statement outputs these selected elements.

Answered By

3 Likes


Related Questions