Computer Science
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)
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
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, 50, 70) print(t[5:-1])
- Blank output( )
- (50,70)
- (50,50,70)
- (50,)
Which of the below given functions cannot be used with nested tuples ?
- index( )
- count( )
- max( )
- sum( )
Fill in the blanks:
Tuples are _________ data types of Python.