Computer Science
What will be the output of the following Python code?
tp = (5,)
tp1 = tp * 2
print(len(tp1))
- 0
- 2
- 1
- Error
Python Tuples
2 Likes
Answer
2
Reason — The "*" operator performs repetition in tuples. tp1 = tp * 2
will result in tp1
as (5, 5) so its length will be 2.
Answered By
3 Likes
Related Questions
What will be the output of the following Python code ?
tp = () 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
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,)