Computer Science
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,)
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
1 Like
Related Questions
What will be the output of the following Python code?
tp = (5,) tp1 = tp * 2 print(len(tp1))
- 0
- 2
- 1
- Error
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)
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)
Which of the below given functions cannot be used with nested tuples ?
- index( )
- count( )
- max( )
- sum( )