KnowledgeBoat Logo

Computer Science

Given tp = (5,3,1,9,0). Which of the following two statements will give the same output?

(i) print( tp[:-1] )
(ii) print( tp[0:5] )
(iii) print( tp[0:4] )
(iv) print( tp[-4:] )

  1. (i), (ii)
  2. (ii), (iv)
  3. (i), (iv)
  4. (i), (iii)

Python Tuples

6 Likes

Answer

(i), (iii)

Reason — Both will yield (5, 3, 1, 9). We can use indexes of tuple elements to create tuple slices as per following format : seq = T[start:stop]

Answered By

2 Likes


Related Questions