KnowledgeBoat Logo

Computer Science

What is the output of the following code?

t = (10, 20, 30, 40, 50, 60, 70)  
print(t[5:-1])
  1. Blank output( )
  2. (10, 20, 30, 40, 50)
  3. (10, 30, 50, 70)
  4. (10, 20, 30, 40, 50, 60, 70)

Python Tuples

25 Likes

Answer

(60,)

Reason — Length of tuple t is 7. t[5 : -1] represents tuple slice t[5 : (7-1)] = t[5 : 6] i.e., the element at index 5. So output is (60,).
Note: There is a misprint in the options provided in the book.

Answered By

18 Likes


Related Questions