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:] )
- (i), (ii)
- (ii), (iv)
- (i), (iv)
- (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
3 Likes
Related Questions
What will be the output of the following Python code?
tp = (5) tp1 = tp * 2 print(len(tp1))
- 0
- 2
- 1
- Error
What will be the output of the following Python code?
tp = (5,) tp1 = tp * 2 print(len(tp1))
- 0
- 2
- 1
- Error
What is the output of the following code ?
t = (10, 20, 30, 40, 50, 50, 70) print(t[5:-1])
- Blank output( )
- (50,70)
- (50,50,70)
- (50,)
What is the output of the following code?
t = (10, 20, 30, 40, 50, 60, 70) print(t[5:-1])
- Blank output( )
- (10, 20, 30, 40, 50)
- (10, 30, 50, 70)
- (10, 20, 30, 40, 50, 60, 70)