Computer Science

What is the output of the following code ?

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

Python Tuples

2 Likes

Answer

(50,)

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 (50,).

Answered By

2 Likes


Related Questions