Computer Science
Which of the following options will not result in an error when performed on types in Python where tp = (5,2,7,0,3) ?
- tp[1] = 2
- tp.append(2)
- tp1=tp+tp
- tp.sum()
Python Tuples
7 Likes
Answer
tp1=tp+tp
Reason — The "+" operator concatenates two tuples and creates a new tuple. First option will throw an error since tuples are immutable, item assignment not supported in tuples. Second and Fourth option will also throw an error since tuple object has no attribute 'append' and 'sum'.
Answered By
2 Likes
Related Questions
What will be the output of following Python code?
tp1 = (2,4,3) tp3 = tp1*2 print(tp3)
- (4,8,6)
- (2,4,3,2,4,3)
- (2,2,4,4,3,3)
- Error
What will be the output of following Python code?
tp1 = (15,11,17,16,12) tp1.pop(12) print(tp1)
- (15,11,16,12)
- (15,11,17,16)
- (15,11,17,16,12)
- Error
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